Macro to loop through column and find match in workbook then return value from same row

beenbee

New Member
Joined
Nov 20, 2013
Messages
4
Hi There,
I have not worked with macros in ages.
I have been trying to adapt the following macro to - Step through column A of Sheet1 and for each value, search for the matching value in any of the other sheets in the workbook.
- When a match is found, return a value from the same row as the macth but from column F.
The following code works for the first value in Column A but doesnt loop through.

VBA Code:
Sub Return_Results_Entire_Workbook()

searchValueSheet = "Sheet2"

searchValue = Sheets(searchValueSheet).Range("A1").Value

returnValueOffset = 5

outputValueSheet = "Sheet2"

outputValueCol = 2

outputValueRow = 1

Sheets(outputValueSheet).Range(Cells(outputValueRow, outputValueCol), Cells(Rows.Count, outputValueCol)).Clear


wsCount = ActiveWorkbook.Worksheets.Count

For I = 1 To wsCount

    
    
    If I <> Sheets(searchValueSheet).Index And I <> Sheets(outputValueSheet).Index Then
    
        Set Rng = Worksheets(I).Cells.Find(What:=searchValue, _
                LookIn:=xlValues, _
                LookAt:=xlWhole, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, _
                MatchCase:=False)
                
        If Not Rng Is Nothing Then
        
            rangeLoopAddress = Rng.Address
            
            Do
                Set Rng = Sheets(I).Cells.FindNext(Rng)
                Sheets(outputValueSheet).Cells(Cells(Rows.Count, outputValueCol).End(xlUp).Row + 1, outputValueCol).Value = Sheets(I).Range(Rng.Address).Offset(0, returnValueOffset).Value
            Loop While Not Rng Is Nothing And Rng.Address <> rangeLoopAddress
        
        End If
    
    End If

Next I


End Sub

Any help would be greatly appreciated!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). Also, what is the name of the destination sheet and where on that sheet do you want to paste the value from the same row as the match?
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,835
Members
449,471
Latest member
lachbee

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