Returning entire row where value is found?

XcelNoobster

New Member
Joined
Jun 7, 2022
Messages
40
So I have a macro that searches Ids in a a couple sheets and outputs the location of each Id in another sheet. Currently right now, it only returns sheet name and address where the Id is found. How would I return the entire row as well?

VBA Code:
Sub findIds()
    Application.ScreenUpdating = False
    Dim srcRng As Range, rng As Range, sAddr As String, fnd As Range, ws As Worksheet, x As Long: x = 1
    Set srcRng = Sheets("IDs").Range("A2", Sheets("IDs").Range("A" & Rows.Count).End(xlUp))
    
    For Each rng In srcRng
        For Each ws In Sheets
            If ws.Name <> "IDs" And ws.Name <> "Results" Then
                Set fnd = ws.Cells.Find(rng, LookIn:=xlValues, lookat:=xlPart)
                If Not fnd Is Nothing Then
                    sAddr = fnd.Address
                    Do
                        With Sheets("Results")
                            .Range("A" & x) = fnd
                            .Range("B" & x) = fnd.Address
                            .Range("C" & x) = ws.Name
                            x = x + 1
                        End With
                        Set fnd = ws.Cells.FindNext(fnd)
                    Loop While fnd.Address <> sAddr
                    sAddr = ""
                End If
            End If
        Next ws
    Next rng
    
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Since there is no information on how to determine where to paste the information, and start and end columns for the source I have made some assumptions. See if this works for you.

VBA Code:
                       Dim rngWs as Range         ' Put this with your other Dim statements

                        With Sheets("Results")
                            .Range("A" & x) = fnd
                            .Range("B" & x) = fnd.Address
                            .Range("C" & x) = ws.Name
                          
                            Set rngWs = intersect(fnd.EntireRow, fnd.CurrentRegion)
                            rngWs.Copy
                             .Range("D" & x).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                            x = x + 1
                        End With
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,121
Members
453,021
Latest member
Justyna P

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