Forum Discussion
Search for a value in entire workbook, return the entire row where value was found
Hello All,
Example: I have 10 Invoice numbers (C093705926 C093705927 C093725527 C093750757 C093750759 C093769955 C093769956 C093789382 C093808525 C093808526) and need to search these in a workbook where they are all located.
1. Can I search for them at the same time?
2. Even if I cannot search for them at the same time, is it possible for the search to return the entire row "C093705926" is located in?
3. What happens if I have to do this for 200 invoices, will this mess up my workbook?
Thank you!
Try this macro:
Sub ListEm() Dim wbkSource As Workbook Dim wshSource As Worksheet Dim rngSource As Range Dim strAddress As String Dim wbkTarget As Workbook Dim wshTarget As Worksheet Dim varSearch As Variant Dim lngRow As Long Application.ScreenUpdating = False Set wbkSource = ActiveWorkbook Set wbkTarget = Workbooks.Add(xlWBATWorksheet) Set wshTarget = wbkTarget.Worksheets(1) For Each wshSource In wbkSource.Worksheets For Each varSearch In Array("C093705926", "C093705927", "C093725527", _ "C093750757", "C093750759", "C093769955", "C093769956", _ "C093789382", "C093808525", "C093808526") Set rngSource = wshSource.Range("C:C").Find(What:=varSearch, LookAt:=xlWhole) If Not rngSource Is Nothing Then strAddress = rngSource.Address Do lngRow = lngRow + 1 rngSource.EntireRow.Copy Destination:=wshTarget.Range("A" & lngRow) Set rngSource = wshSource.Range("C:C").Find(What:=varSearch, _ After:=rngSource, LookAt:=xlWhole) If rngSource Is Nothing Then Exit Do Loop Until rngSource.Address = strAddress End If Next varSearch Next wshSource Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
- peiyezhuBronze Contributor
https://answers.microsoft.com/en-us/msoffice/forum/all/how-can-i-lookup-and-pull-data-from-specific/47023176-d7a5-4fdb-bbff-b4d61acb5ca7
consolidate all sheets and query by sqlmultiple select checkbox
- filipiovituCopper ContributorThe Invoice Numbers are located in Column C in sheets in the same workbook,
the output should be a literal copy of the row, which is 39 cells longThanks. How many sheets do you want to search, and is this fixed or variable?