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.
Any help would be greatly appreciated!
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!