错误:对象变量或未设置块变量
代码:
x.Worksheets.Add().Name = "ab"
x.Worksheets.Add().Name = "bc"
LastRow = x.Sheets("Summary").Columns("A").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
Dim pos As Range
For j = 1 To LastRow
Set pos = x.Sheets("Summary").Range("A1:X" & j).Find(What:="SAP_ALL", LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False)
a = pos.Column
Next j
错误在a = pos.Column
答案 0 :(得分:1)
如果Find
操作找不到任何内容,则pos
将为Nothing
。
你需要一个保护条款:
If Not pos Is Nothing Then
a = pos.Column
End If