正如标题所说,这是否可能以及如何?
我找到了一个.Find
函数来搜索我想要的值的列,那么是否可以将所有地址保存在一个数组中?
代码如下所示:
Set wsRaw = Worksheets("raw_list")
Set oRange = wsRaw.Columns(PhaseCol)
SearchString = "control"
Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell
FoundAt = aCell.Address
Do While ExitLoop = False
Set aCell = oRange.FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
FoundAt = FoundAt & ", " & aCell.Address
Else
ExitLoop = True
End If
Loop
Else
MsgBox SearchString & " not Found"
End If
MsgBox "The Search String has been found these locations: " & FoundAt
Exit Sub
至于现在我有一个MsgBox
只是为了展示结果。这个想法是尽可能将结果存储在一个数组中。