VBA中用Match定位行后调用CountBlank统计空单元格报错求助
Fixing the CountBlank Error in Your VBA Code
First, let’s break down why your current CountBlank line is throwing an error—there are two key issues to fix:
- Incorrect function name: You used
CountBlank_(with a trailing underscore) but the valid VBA WorksheetFunction is simplyCountBlank. - Wrong range syntax: When defining a range between two cells, you need to pass both cells as a single argument to the
Rangemethod, not two separate arguments.
Here’s the corrected version of your code, plus a safety check to handle cases where the Match function doesn’t find the "Date" string:
iCounterFilled01 = 0 On Error Resume Next iCounterFilled01 = Application.WorksheetFunction.Match("Date", wksSource01.Range("A:A"), 0) On Error GoTo 0 ' Corrected CountBlank logic with error handling If iCounterFilled01 > 0 Then iEmptyCells01 = WorksheetFunction.CountBlank(wksSource01.Range(wksSource01.Cells(1, 1), wksSource01.Cells(iCounterFilled01, 8))) Else MsgBox "The 'Date' header was not found in column A." End If
Key Details:
- The
Rangemethod now properly accepts two cells (Cells(1,1)toCells(iCounterFilled01,8)) as a single argument to define the rectangular range you want to scan for blanks. - The added
iCounterFilled01 > 0check prevents invalid range errors if theMatchfunction fails to locate "Date" (which would leaveiCounterFilled01set to 0). - Removing the trailing underscore from
CountBlank_aligns with the official WorksheetFunction naming convention.
This should resolve the "incorrect amount of arguments or incorrectly assigned property" error you’re encountering.
内容的提问来源于stack exchange,提问作者Questionairee
相关产品推荐
相关产品推荐

