尝试使用Range来确定单元格是否等于值,得到运行时错误1004

With wbImportFile.Sheets(1) .Range(Cells(iFirstRow + 464, iFirstColumn)).Select If Not Selection.Value = "" Then MsgBox ("This cam has an offset") End If End With 

所有,我想确定如果我导入的文件中的特定单元格有一个值。 wbImportFile是一个Workbookvariables,而iFirstRow和iFirstColumn是Longvariables(在前面的代码中计算)。

我只是想确定是否位于iFirstRow +第464行和iFirstColumn的单元格是空的,当我这样做,我得到错误的第二行是运行时错误1004“应用程序定义或对象定义的错误。 “

我也试过没有with语句的代码:

 If Not Range(Cells(iFirstRow + 464, iFirstColumn)).Value = "" Then MsgBox ("This cam has an offset") End If 

但我得到同样的错误。

谁能帮我?

试试这个代码:

 With wbImportFile.Sheets(1) If Not .Cells(iFirstRow + 464, iFirstColumn).Value = "" Then MsgBox "This cam has an offset" End If End With 

您可以像这样Range("A1:A10")Range(Cells(1,1),Cells(10,1))使用Range对象,但不能以这种方式使用Range对象: .Range(Cells(..)) 。 你应该简单地使用.Cells()来代替。