Use Range Find Method in a specific column

后端 未结 2 1384
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 05:24

I have been tinkering with this for a while now, I have the below code working but it searches more than I would like it to. I would like it to just search column C and not the

2条回答
  •  一向
    一向 (楼主)
    2021-01-21 05:59

    Your problem is the use of ActiveCell which if happens to be not within C1:C10000 will return nothing. Try this:

    Dim searchRng As Range: Set searchRng = Sheets("State Agent List").Range("C1:C10000")
    Dim r As Range
    Set r = searchRng.Find(What:=ComboBox22.Value, After:=searchRng(searchRng.Count))
    

    The argument searchRng(searchRng.Count) pertains to the last cell of the Range you're working on. It works but it can be written explicitly this way:

    searchRng.Cells(searchRng.Cells.Count)
    

    Why do we need to set the After argument to the last cell?
    Main reason is for the search to begin from the very first cell. HTH

提交回复
热议问题