OK, I have a several workbooks in a folder that I need to write a macro that will search these workbooks worksheet by worksheet and alert the user that a match has been found.
There are many columns in these worksheets but the ones I'm focusing on is two columns next to one another in a Lastname Firstname format. Like:
Doe John
Doe Jane
Using some code I found, I am looping through the worksheets then doing a cells.find command like so:
Now if I have John Doe in several worksheets it will find then and open the msgbox. But after so many it will give an error that "Activate method out of range class". I'm assuming that the loop has gotten to a spreadsheet (say the 5th out of 5 sheets) and has no more sheets to search and gives the error.
Also the msgbox opens, say four times if there are 4 sheets even though the condition only matches in say, 2.
I know this is probably both confusing and "newbieish" but I have been peggin away at this since Friday I'm no futher along than when I started.
I took this task because I work in VB .Net but this is world away....
Thanks for any help...
There are many columns in these worksheets but the ones I'm focusing on is two columns next to one another in a Lastname Firstname format. Like:
Doe John
Doe Jane
Using some code I found, I am looping through the worksheets then doing a cells.find command like so:
Code:
Dim FirstName as string
Firstname = "John"
For Each WS In Worksheets
With WS.Cells
Set Cell = .Find(What:="Doe",LookIn:=xlValues,LookAt: _
=xlPart,MatchCase:=False, SearchOrder:=xlByColumns)
If Not Cell Is Nothing And Cell.Offset(0, 1) = FirstName Then
FirstAddress = Cell.Address
MsgBox "Name Found"
Cell.Activate
Do
Counter = Counter + 1
ReDim Preserve FindCell(1 To Counter)
ReDim Preserve FindSheet(1 To Counter)
ReDim Preserve FindWorkBook(1 To Counter)
ReDim Preserve FindPath(1 To Counter)
ReDim Preserve FindText(1 To Counter)
FindCell(Counter) = Cell.Address(False, False)
FindText(Counter) = Cell.Text
FindSheet(Counter) = WS.Name
'FindWorkBook(Counter) = WB.Name
'FindPath(Counter) = WB.FullName
Set Cell = .FindNext(Cell)
Loop While Not Cell Is Nothing And Cell.Address <> FirstAddress
End If
End With
Next
Now if I have John Doe in several worksheets it will find then and open the msgbox. But after so many it will give an error that "Activate method out of range class". I'm assuming that the loop has gotten to a spreadsheet (say the 5th out of 5 sheets) and has no more sheets to search and gives the error.
Also the msgbox opens, say four times if there are 4 sheets even though the condition only matches in say, 2.
I know this is probably both confusing and "newbieish" but I have been peggin away at this since Friday I'm no futher along than when I started.
I took this task because I work in VB .Net but this is world away....
Thanks for any help...