How to find a value in an excel column by vba code Cells.Find

前端 未结 4 1812
情歌与酒
情歌与酒 2020-11-30 03:38

I have to find a value celda in an Excel sheet. I was using this vba code to find it:

Set cell = Cells.Find(What:=celda, After:=ActiveCell,          


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 04:19

    Just for sake of completeness, you can also use the same technique above with excel tables.

    In the example below, I'm looking of a text in any cell of a Excel Table named "tblConfig", place in the sheet named Config that normally is set to be hidden. I'm accepting the defaults of the Find method.

    Dim list As ListObject
    Dim config As Worksheet
    Dim cell as Range
    
    
    Set config = Sheets("Config")
    Set list = config.ListObjects("tblConfig")
    
    'search in any cell of the data range of excel table
    Set cell = list.DataBodyRange.Find(searchTerm)
    
    If cell Is Nothing Then
        'when information is not found
    Else
        'when information is found
    End If
    

提交回复
热议问题