Excel VBA查找值列表之一的单元格地址

时间:2019-05-14 19:37:14

标签: excel vba

我有一个字符串值列表。这些字符串值之一存在于我的数据范围内。我想不执行循环就获取该字符串存在的单元格地址。

Microsoft documentation indicates 。查找(内容,LookIn ... 什么

  

要搜索的数据。可以是字符串或任何Microsoft Excel数据类型。

所以我尝试如下使用ArrayList,因为arraylist在实现的其他部分很有帮助。

Dim staSearchList As Object
Set staSearchList = CreateObject("System.Collections.ArrayList")
staSearchList.Add "Sta Pending Secs"
staSearchList.Add "Adjusted Sta Wait Secs"
staSearchList.Add "STATION WAIT SECONDS"

With Worksheets(transSheet.Name).Range(titleRangeStr)
    'Set staWait = .Find(staSearchList, LookIn:=xlValues)
    Set staWait = .Find(staSearchList, LookIn:=xlValues)
    If Not staWait Is Nothing Then
        adjCol = staWait.Column
    Else
        iConfirmMsg = MsgBox("Station Wait Column not found. Exiting. ", vbInformation)
        GoTo exitCreateBrackets
    End If
End With

我收到的错误消息是运行时错误

  

缺少参数没有默认值

是否可以在.Find方法中使用arraylist?是否有另一种方法可以在一个单元格范围内搜索多个值,并获得其中一个值存在的单元格地址,而无需使用循环?在我看来,Excel是如此面向范围的,我不需要循环。 ;-)

为澄清和回答问题,这是搜索标题的多行。并且只有一个值存在,但是有可能不存在。我绝对可以用循环来实现,我很好奇是否有更好的方法,将其内置到Excel / vba中。

0 个答案:

没有答案