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

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
Hmm not returning anything

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

Some videos you may like

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
Joined
Mar 6, 2018
Messages
105
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
Joined
Jan 26, 2015
Messages
751
Office Version
2016
Platform
Windows
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
 

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
751
Office Version
2016
Platform
Windows
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
Joined
Mar 6, 2018
Messages
105
I have some more questions to add onto this if you are willing to help!?
 

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105
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
 

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
751
Office Version
2016
Platform
Windows
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
 

Forum statistics

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

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top