Range.Find in VBA Excel

前端 未结 2 1812
天命终不由人
天命终不由人 2021-01-27 08:49

I\'m trying to perform a \"find\" in a Excel sheet with this instruction:

Set Found = Columns(2).Find(What:=value_to_find, After:=ActiveCell, LookIn:=xlFormulas,         


        
相关标签:
2条回答
  • 2021-01-27 09:14

    Exactly as @barrowc commented.

    This works although not sure of exact requirements:

    Sub xxx()
    
    Dim value_to_find As String
    value_to_find = "fooBar"
    
    Dim r As Range
    Set r = ActiveCell.EntireColumn.Find( _
        What:=value_to_find, _
        After:=ActiveCell, _
        LookIn:=xlFormulas, _
        LookAt:=xlPart, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, _
        MatchCase:=False, _
        SearchFormat:=False)
    
    MsgBox r.Address
    
    End Sub
    

    enter image description here

    0 讨论(0)
  • 2021-01-27 09:30

    [RESOLVED] Many Thanks everyone, I resolved my question with the Ralph's support.

    The variable Found (in your code) must be of type variant. So, if you explicitly set Dim Found as variant then your code should work.

    0 讨论(0)
提交回复
热议问题