嗨,我有两个公式,我试图运行,但努力使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,然后退出sub。
发布于 2014-10-06 09:28:42
如果您试图根据“范围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
希望这能回答你的问题。
发布于 2014-10-06 07:25:03
为了计算给定范围内的所有非空白单元格,可以使用:
If ActiveSheet.Range("A2:A14").SpecialCells(xlCellTypeConstants).Count < 13 Then
https://stackoverflow.com/questions/26219165
复制相似问题