Code:
Sub SearchData()
Dim strComboSelection As String
Dim lngIndex As Long, c As Long
Dim ShtsPuchase, ShtSales As String
Dim ka, k(), i As Long, n As Long
Dim x, j As Long, r As Long
Dim m As Long, SearchKeys As String
ShtsPuchase = Array("Sheet3", "Sheet4") '<< adjust sheet names
ShtSales = "Sheet5" '<< adjust sheet names
SearchKeys = Worksheets("find").TextBox1.Value
If Len(SearchKeys) Then
SearchKeys = "{""" & Replace(Replace(SearchKeys, Chr(10), """;"""), Chr(13), vbNullString) & """}"
With Worksheets("find").ComboBox1
lngIndex = .ListIndex
strComboSelection = LCase$(.List(lngIndex, 0))
End With
Select Case strComboSelection
Case "purchase"
ReDim k(1 To 1000, 1 To 8)
n = 1
For j = LBound(ShtsPuchase) To UBound(ShtsPuchase)
With Worksheets(ShtsPuchase(j))
r = .Range("a" & .Rows.Count).End(xlUp).Row
ka = .Range("a7:g" & r)
End With
For c = 1 To UBound(ka, 2): k(1, c) = ka(1, c): Next: k(1, c) = "Label"
For i = 2 To UBound(ka, 1)
x = False
x = Evaluate("isnumber(lookup(9.9999e+307,search(""" & ka(i, 6) & """," & SearchKeys & ")))")
If x Then
n = n + 1
For c = 1 To UBound(ka, 2)
k(n, c) = ka(i, c)
Next: k(n, c) = ShtsPuchase(j)
End If
Next
Erase ka
Next
Case "sales"
ReDim k(1 To 1000, 1 To 12)
n = 1
With Worksheets(ShtSales)
r = .Range("a" & .Rows.Count).End(xlUp).Row
ka = .Range("a7:l" & r)
End With
For c = 1 To UBound(ka, 2): k(1, c) = ka(1, c): Next
For i = 2 To UBound(ka, 1)
x = False
x = Evaluate("isnumber(lookup(9.9999e+307,search(""" & ka(i, 6) & """," & SearchKeys & ")))")
If x Then
n = n + 1
For c = 1 To UBound(ka, 2)
k(n, c) = ka(i, c)
Next
End If
Next
End Select
If n Then
Application.ScreenUpdating = False
With Worksheets("Find")
.Range("a7", .Cells(7, 1).SpecialCells(11)).ClearContents
With .Range("a7").Resize(n, UBound(k, 2))
.Value = k
.Sort .Cells(2, 2), 1, Header:=1
.EntireColumn.AutoFit
End With
End With
Else
MsgBox "No records found", vbInformation
With Worksheets("Find")
.Range("a7", .Cells(7, 1).SpecialCells(11)).ClearContents
End With
End If
Application.ScreenUpdating = True
End If
End Sub
Bookmarks