VBA to search for multiple items in workbook

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
199
Hi Guys

I have a list of 200 unique strings, I need to find which of these is not contained in a workbook with multiple tabs, can anyone advise on a quick way to do this please?

thanks

Noel
 
Hi Noel,
On the last two posts... yeah we can make it do that.

I have a handful of meetings this morning and a couple this afternoon so it ain't lookin' good for today but if you're not in too big a hurry I'll take a look at it in a day or so. I know I already use a routine that will search through the entire workbook so that particular wheel already exists, we'll just need to beat it a little rounder is all.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
no worries at all, was just thinking to myself when I ran "why didn't I just do a vlookup and stop bothering the good folk at the forum" but yeah to search the whole wb would be the ultimate goal.

appreciate all the help you have given so far and appreciate any time you can spare whenever.

Noel
 
Upvote 0
Oh, I thought you'd settled on using vlookup... :eeek:

For vba, how about something like this?
Code:
Sub SearchSheetsWASHAndUBS()
Dim LstRw As Long, SrchRng As Range, SrchTrm As Range

'''Amend the next line to the real range where your values to search for reside.
Set SrchRng = Range("A1:A200")

For Each SrchTrm In SrchRng

  With Sheets("WASH")
    LstRw = .Cells(Rows.Count, "N").End(xlUp).Row
    On Error Resume Next
    Set Found = .Range("N1:N" & LstRw).Find(SrchTrm, lookat:=xlContents)
    If Not Found Is Nothing Then
      MsgTxt = SrchTrm & "  is located on '" & .Name & "' sheet in cell " & Found.Address(0, 0)
      MsgBox MsgTxt
      SrchTrm.Font.ColorIndex = 3
    End If
    On Error GoTo 0
  End With
  
  With Sheets("UBS")
    LstRw = .Cells(Rows.Count, "N").End(xlUp).Row
    On Error Resume Next
    Set Found = .Range("N1:N" & LstRw).Find(SrchTrm, lookat:=xlContents)
    If Not Found Is Nothing Then
      MsgTxt = SrchTrm & "  is located on '" & .Name & "' sheet in cell " & Found.Address(0, 0)
      MsgBox MsgTxt
      SrchTrm.Font.ColorIndex = 3
    End If
    On Error GoTo 0
  End With
  
Next SrchTrm

End Sub

I don't know where your list of (200 or so) search terms are located so this assumes it is in range A1:A200 of the active sheet.

Does that get you any closer?
 
Upvote 0
yep that is perfect, thanks a lot

FYI have omitted the Msg Box for now but like the way this works and will be sure to hold on to it for future reference

thanks again
 
Upvote 0
:laugh:
Yeah, I put those in basically just for testing. Only realized after posting it that I forgot to remove them.

Anyway, glad it helped.
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,212
Members
453,151
Latest member
Lizamaison

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