2014-10-06 100 views
0

嗨我所有我有2公式我试图运行,但努力让COUNTIF计算只有当单元格不是空白。计数,如果单元格不为空

Sheets("Home").Select 
If Range("A2:A14").Count = "13" Then 

MsgBox "Current Load Full Please Complete & Export", vbCritical 

Exit Sub 

End If 

第二代码

Sheets("Home").Select 
If Range("A2:A14").Count < "13" Then 

MsgBox "Shipment is short do you want to continue?", vbCritical vbYesNo 

Exit Sub 

End If 

二号代码,如果vbYes那么如果vbNo然后退出子运行代码。

+0

我不明白你的问题是什么。你有没有进行过任何研究? – Vogel612 2014-10-06 15:17:13

+0

对不起。使用上面的代码将计算所有空白单元以及填充的单元格。我需要能够只计算含有内容的单元格。 – 2014-10-06 15:23:08

回答

1

如果你试图做取决于条件“中的区域A2的所有细胞的一些行动:A14是否填充“ - 那么这个代码可能是答案。

Sub check_count() 

Sheets("Home").Select 

Dim myRange As Range 
Set myRange = Worksheets("Home").Range("A2:A14") 

'using excel's built in function CountA to check count of non-blank cells 
'if the count is 13 - then msgbox 
If Application.WorksheetFunction.CountA(myRange) = 13 Then 
    MsgBox "Current Load Full Please Complete & Export", vbCritical 
    Exit Sub 
'if the count is less then 13 - then do following 
Else: 
    msg1 = MsgBox("Shipment is short do you want to continue?", vbYesNo) 
    If msg1 = vbYes Then 
     MsgBox "Enter missing products in A2:A14" 'you can run some code here as well 
    Else: Exit Sub 
    End If 
End If 

End Sub 

希望这回答你的问题。

+0

谢谢你完美的作品。 – 2014-10-07 05:18:05

0

为了计算在给定范围内的所有非空白单元格,你可以使用:

If ActiveSheet.Range("A2:A14").SpecialCells(xlCellTypeConstants).Count < 13 Then 
+1

作为一个补充....不要使用字符串来表示数字类型 – Vogel612 2014-10-06 15:26:05

相关问题