我试图在 Excel 工作表的列中查找特定值,然后在右侧三列中添加一个值 (=1)。
My code:
Sub AddNote()
ActiveSheet.Range("F:F").Find(What:="Cat").Select
Selection.Offset(0, 4).Value = 1
End Sub
只有我得到:
错误消息 91:`未设置对象变量或 With 块变量。
我的命令有什么问题吗?
看看这个 :
Sub test_IngaB()
Dim FirstAddress As String, cF As Range, LookForString As String
LookForString = "Cat"
With ThisWorkBook.Sheets("Sheet's name").Range("F:F")
.Cells(1,1).Activate
'First, define properly the Find method
Set cF = .Find(What:=LookForString, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
'If there is a result, keep looking with FindNext method
If Not cF Is Nothing Then
FirstAddress = cF.Address
Do
cF.Offset(0, 3).Value = 1
Set cF = .FindNext(cF)
'Look until you find again the first result
Loop While Not cF Is Nothing And cF.Address <> FirstAddress
End If
End With
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)