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(... ?
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
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>
 

grahamj

Board Regular
Joined
Feb 18, 2003
Messages
101
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.
 

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
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>
 

Watch MrExcel Video

Forum statistics

Threads
1,122,207
Messages
5,594,843
Members
413,944
Latest member
3xc3ln00b

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
Top