Find a value across several worksheets

grahamj

Board Regular
Joined
Feb 18, 2003
Messages
101
I have a workbook with several worksheets each containing codes in column A.
I read another file of codes and values, and for each line I want to find the code in whatever worksheet it appears and add the values into other columns.
How do I do a Find (or Match ...) across several worksheets?

I am trying
Sheets(Array("Alpha","Beta","Gamma"))
but what next? Columns("A:A").Find(... ?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi!
Try this!
This will loop thru all worksheet and try to find a match in column A

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> findx()
<SPAN style="color:#00007F">Dim</SPAN> Sht <SPAN style="color:#00007F">As</SPAN> Worksheet
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> Sht <SPAN style="color:#00007F">In</SPAN> ThisWorkbook.Sheets
<SPAN style="color:#00007F">With</SPAN> Sht.Range("A:A")
    <SPAN style="color:#00007F">Set</SPAN> c = .Find("your query", LookIn:=xlValues)
    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> c <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'something is found</SPAN>
    <SPAN style="color:#007F00">'do what you want to do if you found something</SPAN>
    <SPAN style="color:#00007F">Else</SPAN>
    
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>


<SPAN style="color:#00007F">Next</SPAN> Sht
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Thanks. Getting there.

Now for the refinement.
There's always something that we don't tell you the first time round.
This time it is that there are also a number of worksheets that I DON'T want to search in.

So do I specify an array (my current fixation) of sheets to step through?
Somehow I think I have to name the individual sheets.
 
Upvote 0
so. there are sheet/s in which you do not want to cheeck.
Try this. but you got to type all sheet name that you
wan to check.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> findx()
<SPAN style="color:#00007F">Dim</SPAN> Shtname()
Shtname = Array("Sheet1", "sheet2")
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> Sht <SPAN style="color:#00007F">In</SPAN> Shtname
<SPAN style="color:#00007F">With</SPAN> Worksheets(Sht).Range("A:A")
    <SPAN style="color:#00007F">Set</SPAN> c = .Find("your query", LookIn:=xlValues)
    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> c <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'something is found</SPAN>
    <SPAN style="color:#007F00">'do what you want to do if you found something</SPAN>
    MsgBox "i found one in " & Sht
    <SPAN style="color:#00007F">Else</SPAN>
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">Next</SPAN> Sht
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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