Macro To Loop Through Worksheets To Match Value And Return All Results

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hi Everyone,

I am trying to build a macro that takes the value in Sheet name - "Report" Cell "A2" (this is going to be a employees name), looks through all the sheets in my workbook and returns each project name that their name is in one of the sheets going down from Cell "A5". So If their name appears 3 times within all the tabs in my workbook I want it to return the project name which will be in Cell E20 in all the other tabs.

So if I were to do this within excel and NOT VBA it would look like this -
=INDEX('1'!E20:E24,MATCH('Report'!A2,'1'!$G$20:$G$24))

The '1' is the name of the tab that it has the info i need to match to. (All the worksheets are numbered 1,2,3,4,5, and will continue growing as more projects come in)
I need the above formula to loop through all workbooks and once it finds a match to post the result in cell A5 and keep going down from there for each match that it finds

Thank you for your help!
 
Hmm not returning anything

is it only gonna paste if it finds more than or equal to 3?
 
Last edited:
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
So i changed flipped the sign to less than and got it, however it only pastes the first return rather than all of them
 
Upvote 0
Hmm not returning anything

odd it worked for me
i made a sheet named "Report" and put "Paul" into cell A2
I then made 5 blank sheets
i then made 5 sheets with a 9x9 grid of names that differed
I made it so that '1' '2' and '5' contained "Paul" 3 times or more

i posted the cells i had in E20 on those 3 sheets into cells A5-A8
if you're not getting any error messages either please double check the following:

-Your sheet is named "Report"
-The name value is A2 and the cell were searching for are exact matches (i expect this to be the problem)
-There are no blank rows/columns
 
Upvote 0
So i changed flipped the sign to less than and got it, however it only pastes the first return rather than all of them

that would mean the value in cell A2 appears in one sheet less than 3 times
 
Upvote 0
So on those numbered tabs next to column E, i have project roles in cells F20:F24... I tried adjusting that line you sent with

Sheets("Report").Cells(5 + p, 1).Value = Sheets(i).Range("E20").Value

to this:

Sheets("Report").Cells(5 + p, 1).Value = Sheets(i).Range("F20:F24").Value

Howeverit only returns the value in F20.

In this numbered tabs:

F20 = Project Lead
F21 = Project Support
F22 = Project Support2
F23 = Project Support3
F24 = Project Support4
 
Upvote 0
Sheets("Report").Cells(5 + p, 1).Value = Sheets(i).Range("F20:F24").Value

Howeverit only returns the value in F20.

thats because Cells() by itself refers to a single cell location
while range() can refer to multiple cells

to fix this you would want to define a range on the report sheet with a starting cell and an ending cell just like you did for sheets(i)

Code:
Sheets("Report").Range(Cells(5 + p, 1), Cells(10 + p, 1)).Value = Sheets(i).Range("F20:F24").Value
p = p + 5

the reason we want to +5 our counter is because we don't want our range for multiple matches to overlap
this is untested but should work
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,249
Members
448,879
Latest member
oksanana

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