I use a userform to search in all worksheets and get sheet name for the found items.
My question is , i don't want the vba to search in all sheets, i just want to search in the first 4 sheets only , or to specify sheets names that i want to search in
i'm using this code , so please if you could assist on how to modify this code to make it search in only specific sheets
Quote Private Sub TextBox1_Change()
Dim searchkey As Variant Dim wb As Workbook Dim ws As Worksheet Dim rng As Range Dim cvalue As Variant
searchkey = TextBox1.Value Set wb = ThisWorkbook
Me.ListBox1.Clear
For Each ws In wb.Worksheets
Set rng = ws.UsedRange
For Each cvalue In rng
If InStr(1, cvalue, searchkey, vbTextCompare) > 0 Then On Error Resume Next ListBox1.AddItem cvalue ListBox1.List(ListBox1.ListCount - 1, 1) = ws.Name 'ListBox1.List(ListBox1.ListCount - 1, 2) = cvalue.Address
End If
Next cvalue
Next ws
End Sub UnQuote
I tried to make the VBA search only in the first 4 sheets , but actually it is searching in all sheets in workbook including sheets of power query and pivot tables