Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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
Excel 获取错误“;对象变量或未设置块变量";查找列号时_Excel_Vba - Fatal编程技术网

Excel 获取错误“;对象变量或未设置块变量";查找列号时

Excel 获取错误“;对象变量或未设置块变量";查找列号时,excel,vba,Excel,Vba,我想找到第1行中文本“备注”所在单元格的列号。在我的例子中,第1行和第2行合并。 我使用下面的逻辑查找列号,但我得到运行时错误91;对象变量或块变量未设置 Dim lnRow As Long, lnCol As Long lnRow = 1 lnCol = Sheet1.Cells(lnRow, 1).EntireRow.Find(What:="Remarks", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, Searc

我想找到第1行中文本“备注”所在单元格的列号。在我的例子中,第1行和第2行合并。 我使用下面的逻辑查找列号,但我得到
运行时错误91;对象变量或块变量未设置

Dim lnRow As Long, lnCol As Long

lnRow = 1
lnCol = Sheet1.Cells(lnRow, 1).EntireRow.Find(What:="Remarks", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column

我在这里做错了什么?

链接
。当
查找不成功时,此处末尾的列
将失败:

测试
查找
是否以以下方式成功,然后返回

Dim remarksRng as Range
Set remarksRng = Sheet1.Rows(lnRow).Find(What:="Remarks", _
                      LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, _
                      SearchDirection:=xlNext, MatchCase:=False)

If Not remarksRng Is Nothing Then
    lnCol = remarksRng.Col
Else
    ' not found; handle here
End If

查找不成功时,此处末尾的链接
。列
将失败:

测试
查找
是否以以下方式成功,然后返回

Dim remarksRng as Range
Set remarksRng = Sheet1.Rows(lnRow).Find(What:="Remarks", _
                      LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, _
                      SearchDirection:=xlNext, MatchCase:=False)

If Not remarksRng Is Nothing Then
    lnCol = remarksRng.Col
Else
    ' not found; handle here
End If

您假设
查找
成功。是。。我认为它将永远成功。即使查找成功,我也会遇到此错误您是否有代码名为
Sheet1
的工作表?您假设
查找
成功。是的。。我认为它将永远成功。即使查找成功,我也会遇到此错误您是否有代码名为
Sheet1
的工作表?