I have the code below that searches the entire workbook for a value entered in C3 of sheet LOOKUP and returns the results specified in row 6 of the same sheet. What I need it to do, is to search for a value only on specific sheets in the workbook (and preferably in the column I specify) and then return the results. I was hoping to be able to manage the sheets it searches through by entering the sheet names in a column of a worksheet that would only have that information (kind of a control panel). That way, people can add or remove sheets from the search without going into the VBA.
So far, no luck. Any ideas are appreciated greatly.
So far, no luck. Any ideas are appreciated greatly.
Code:
Sub ID_Lookup()
Dim rng As Range, Cel, ms As Worksheet, ws As Worksheet, k, NR&
Set ms = Sheets("LOOKUP")
Application.ScreenUpdating = 0
Sheets("LOOKUP").Range("C6:E7").ClearContents
With ms
Cel = .Range("C3")
End With
NR = ms.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1 '+3?
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ms.Name Then
With ws.UsedRange
If Len(Cel) Then
Set rng = .Find(Cel, LookIn:=xlValues, LookAt:=xlPart)
If Not rng Is Nothing Then
k = k & "," & ws.Name
rng.Offset(, -13).Copy
ms.Range("C" & NR).PasteSpecial xlValues
rng.Copy
ms.Range("D" & NR).PasteSpecial xlValues
ms.Range("E" & NR) = Mid(k, 2)
Range("C3").Select
Range("C3").ClearContents
End If
With Range("D6")
.Value = Replace(.Value, "&", ", ")
End With
End If
End With
End If
Next
If Range("C6").Value = "" Then MsgBox ("Number " & Cel & " not found.")
If Range("C6").Value = "" Then Sheets("LOOKUP").Range("C3").ClearContents
Application.CutCopyMode = 0
Set ms = Nothing
Set rng = Nothing
Application.ScreenUpdating = True
End Sub