You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

  1. Incorrect function name: You used CountBlank_ (with a trailing underscore) but the valid VBA WorksheetFunction is simply CountBlank.
  2. Wrong range syntax: When defining a range between two cells, you need to pass both cells as a single argument to the Range method, 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 Range method now properly accepts two cells (Cells(1,1) to Cells(iCounterFilled01,8)) as a single argument to define the rectangular range you want to scan for blanks.
  • The added iCounterFilled01 > 0 check prevents invalid range errors if the Match function fails to locate "Date" (which would leave iCounterFilled01 set 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 21:27:53