Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 试图确定单元格是否等于使用范围的值,获取运行时错误1004_Vba_Excel_Excel 2010 - Fatal编程技术网

Vba 试图确定单元格是否等于使用范围的值,获取运行时错误1004

Vba 试图确定单元格是否等于使用范围的值,获取运行时错误1004,vba,excel,excel-2010,Vba,Excel,Excel 2010,总之,我试图确定我导入的文件中的特定单元格中是否有值。wbImportFile是工作簿变量,iFirstRow和iFirstColumn是长变量(在前面的代码中计算) 我只是想确定位于iFirstRow+464行和iFirstColumn的单元格是否为空,当我这样做时,我在第二行得到一个错误,即运行时错误1004“应用程序定义的错误或对象定义的错误” 我还尝试了没有with语句的代码: With wbImportFile.Sheets(1) .Range(Cells(iFirstRow

总之,我试图确定我导入的文件中的特定单元格中是否有值。wbImportFile是工作簿变量,iFirstRow和iFirstColumn是长变量(在前面的代码中计算)

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

我还尝试了没有with语句的代码:

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
但我也犯了同样的错误

有人能帮我吗?

试试下面的代码:

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

您可以像这样使用
Range
对象
Range(“A1:A10”)
Range(单元格(1,1)、单元格(10,1))
,但不能以这种方式使用
Range
对象:
.Range(单元格(…)
。您只需使用
.Cells()
即可

+1但我想补充一点,您可以将
.Cells
.Range
一起使用,只是不像OP那样。示例:
.Range(.Cells(1,1),.Cells(10,2))
@ARich,谢谢:)你说得对,这正是我想告诉你的:)@ARich哇,多么令人困惑的规则。有时可能是:)从技术上讲,如果您在
.Cells
的末尾添加了
.Address
,您的代码可能会正常工作。示例:
.Range(.Cells(iFirstRow+464,iFirstColumn).Address)
。好了,伙计们,我还是很难理解整个范围,Cells的事情。我已经用下面的更多代码“回答了我自己的问题”。
With wbImportFile.Sheets(1)
    If Not .Cells(iFirstRow + 464, iFirstColumn).Value = "" Then
        MsgBox "This cam has an offset"
    End If
End With