Log in

View Full Version : Search By Worksheet Name And Return Data



Peta
02-09-2008, 05:58 AM
Sorry wrong Forum i am such a looser !!!

I have a separate worksheet for each customer with sales data from each transaction. The worksheets are named after each customer. I am trying to search the worksheet names for the customer and then seach within that specifc worksheet by job description etc. and return the information to a userform.
I have no idea how to do this and is driving me slightly crazy :offwall:

I would really appreciate any help on how to go about this.

herzberg
02-10-2008, 06:50 PM
Here's a loop to search through all the worksheets. As for the second part of searching within the worksheet, it'll be helpful if you can provide additional details like which column/row to search for, etc.

Public Sub SearchSheet()

Dim Activewb As Workbook
Dim TargetSheet As Worksheet
Dim SearchName As String
Dim FoundName As Boolean

SearchName = InputBox("What's ya name?")

Set Activewb = ThisWorkbook
FoundName = False

For Each TargetSheet In Activewb.Sheets
If LCase(TargetSheet.Name) = LCase(SearchName) Then
FoundName = True
Exit For
Else
FoundName = False
End If
Next TargetSheet

If FoundName = False Then
MsgBox "Customer not found."
Exit Sub
Else
'Rest of the code follows
End If

End Sub