Multiple Match - Find VBA

MUKESHY12390

Well-known Member
Joined
Sep 18, 2012
Messages
901
Office Version
  1. 2013
  2. 2011
  3. 2010
  4. 2007
Platform
  1. Windows
Hi All,

got situation --

I have one column (A) and header start from very first row (1) And after several rows header starts again.

so whenever I use Find method it give me second match doesn't give first match.

Code:
Example
'''''I enter text "EmpID" in two cell A1 and A2 and excel gives me only second match 
Sheet1.Activate


    Columns(1).Find(What:="EmpID", After:=Range("A1"), LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
     MsgBox ActiveCell.Address


End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Maybe

Code:
Dim LR As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row
Columns(1).Find(What:="EmpID", After:=Range("A" & LR), LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
MsgBox ActiveCell.Address

M.
 
Upvote 0
you nailed it.... thank you so much.


I had some other way to resolve this issue. but yours solution is really awesome.
 
Upvote 0
Hi All,

got situation --

I have one column (A) and header start from very first row (1) And after several rows header starts again.

so whenever I use Find method it give me second match doesn't give first match.

Code:
Example
'''''I enter text "EmpID" in two cell A1 and A2 and excel gives me only second match 
Sheet1.Activate


    Columns(1).Find(What:="EmpID", [B][COLOR="#FF0000"]After:=Range("A1")[/COLOR][/B], LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
     MsgBox ActiveCell.Address


End Sub
Just so you understand the root of the problem you had... what I highlighted in red is why you had the problem... the search takes place after cell A1, so the headers are not looked at first. The change Marcelo gave you makes the search start after the last cell in the range which force the Find function to wrap around to the beginning of the range for the start of the search.
 
Upvote 0
yes exactly, Even if remove "After" criteria by default it starts from A1 I guess.


Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,974
Messages
6,175,737
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top