VBA错误 – 应用程序定义的pr对象定义的错误使用If时

我在VBA中编写了下面的代码:

Dim Counter As Long Dim Counter_Two As Long Dim Array_Column_Letter(3) As String Array_Column_Letter(0) = "A" Array_Column_Letter(1) = "B" Array_Column_Letter(2) = "C" Array_Column_Letter(0) = "D" For Counter = 0 To LastRow For Counter_Two = 0 To 3 If Worksheets("Sheet1").Cells(Counter, Array_Column_Letter(Counter_Two)).Value = IsEmpty(True) Then MsgBox ("Hi") End If Next Counter_Two Next Counter 

出于某种原因,我收到以下错误:

应用程序定义的pr对象定义的错误

VBA说if语句导致这个错误是有问题的。 我似乎无法弄清楚为什么。 有任何想法吗?

Excel中的范围从“A1”开始而不是“A0”

这条线

 If Worksheets("Sheet1").Cells(Counter, Array_Column_Letter(Counter_Two)).Value = IsEmpty(True) Then 

应该改成

 If Worksheets("Sheet1").Cells(Counter + 1 , Array_Column_Letter(Counter_Two)).Value = IsEmpty(True) Then 

也正确地使用isempty你应该使用它如下

 If IsEmpty(Worksheets("Sheet1").Cells(Counter + 1 , Array_Column_Letter(Counter_Two)).Value) Then 

您得到该错误,因为您正在尝试查找行0.更改您的第一个For语句中的起始值