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

#### rameezl17

##### Board Regular
Hmm not returning anything

is it only gonna paste if it finds more than or equal to 3?

Last edited:

### Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a \$25,000 loan, 5% annual interest, 60 month loan.

#### rameezl17

##### Board Regular
So i changed flipped the sign to less than and got it, however it only pastes the first return rather than all of them

#### DataBlake

##### Well-known Member
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:

-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

#### DataBlake

##### Well-known Member
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

#### rameezl17

##### Board Regular
Nevermind it works! You are awesome! Thank you!

#### rameezl17

##### Board Regular
I have some more questions to add onto this if you are willing to help!?

#### DataBlake

##### Well-known Member
I have some more questions to add onto this if you are willing to help!?
absolutely

#### rameezl17

##### Board Regular
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:

F21 = Project Support
F22 = Project Support2
F23 = Project Support3
F24 = Project Support4

#### DataBlake

##### Well-known Member
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

1,089,334
Messages
5,407,655
Members
403,158
Latest member
Limerick2030