search in multiple sheets

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,494
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi, all
i have data in multiple sheets begins from a2:q all of sheets the same thing the search in sheet1 in range a2 so i would when i search it get data from multiple sheets based on column d in multiple sheets if i clear the range a2 in sheet1 get all data
this output after search
استعلام.xlsx
ABCDEFGHIJKLMNOPQ
1IDEMPLOYEE
21000
3
4
5
6
7ITEM1DATECASEDEP23456CUSTOM7CASE1MONTHNUMBERNAMEDOC
81YESDEP10COMMONFIRST25A15030
92NODEP250COMMONFIRST10A15000
103YESDEP30COMMONFIRST5A16000
114NODEP40COMMONFIRST100BA7000
125YESDEP50COMMONFIRST15BA8000
136NODEP60COMMONFIRST9AA1000
147YESDEP70COMMONFIRST12AA1100
158NODEP80COMMONFIRST25AA1200
SHEET1
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
this is two sheets
استعلام.xlsx
ABCDEFGHIJKLMNOPQR
1ITEM1IDCASEDEP23456CUSTOM7CASE1MONTHNUMBERNAMEDOC
211000YESDEP10COMMONFIRST25A15030
331000YESDEP30COMMONFIRST5A16000
441000NODEP40COMMONFIRST100BA7000
551000YESDEP50COMMONFIRST15BA8000
661000NODEP60COMMONFIRST9AA1000
7711000YESDEP70COMMONFIRST12AA1100
8811000NODEP80COMMONFIRST25AA1200
1






استعلام.xlsx
ABCDEFGHIJKLMNOPQR
1ITEM1IDCASEDEP23456CUSTOM7CASE1MONTHNUMBERNAMEDOC
211000YESDEP10COMMONFIRST10A15030
331500YESDEP30COMMONFIRST22A16000
441400NODEP40COMMONFIRST33BA7000
551000YESDEP50COMMONFIRST44BA8000
661000NODEP60COMMONFIRST9AA1000
7711000YESDEP70COMMONFIRST12AA1100
8811000NODEP80COMMONFIRST25AA1200
2
 
Upvote 0
Put the code in SHEET1 events

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim sh As Worksheet, sh1 As Worksheet
  Dim a As Variant, b() As Variant, nID As Variant, cols As Variant
  Dim lr As Long, lr2 As Long, i As Long, j As Long, k As Long
 
  If Target.Address(0, 0) = "A2" Then
    If Target.CountLarge > 1 Then Exit Sub
    Set sh1 = Sheets("SHEET1")
    nID = Target.Value
    sh1.Rows("8:" & Rows.Count).ClearContents
    cols = Array(1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)
    For Each sh In Sheets
      lr = lr + sh.Range("D" & Rows.Count).End(3).Row
    Next
    ReDim b(1 To lr, 1 To 17)
    '
    For Each sh In Sheets
      If sh.Name <> sh1.Name Then
        a = sh.Range("A2:R" & sh.Range("D" & Rows.Count).End(3).Row).Value2
        For i = 1 To UBound(a, 1)
          If a(i, 4) = IIf(nID = "", a(i, 4), nID) Then
            k = k + 1
            For j = 1 To UBound(a, 2)
              If cols(j - 1) <> 0 Then b(k, cols(j - 1)) = a(i, j)
            Next j
          End If
        Next i
        Erase a
      End If
    Next sh
    '
    If k > 0 Then
      sh1.Range("A8").Resize(k, 17).Value = b
    Else
      MsgBox "No data"
    End If
  End If
End Sub
 
Upvote 0
great code thanks dante but i have aquestion if you don't mind jut curiosity if i decide specific column transfer how is it
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top