Loop with a formula on a dymanic range

BC2019

New Member
Joined
Mar 25, 2019
Messages
4
I have a need to loop through a dynamic range with a formula preferrable. If i have to use a macro i can, but would rather not if possible just for ease of maintenance down the road.

My situation is this:

"Names" would have a list of names repeated a number of times (variable but is based on the number of items in "Numbers" and can be obtained with a count. I've done this with no problem already using =INDEX(Names!$B$2:$B$400,INT((ROWS($A$7:A11)-1)/COUNTIF(Final$C$2:$C$1000,11000)+1)). The number of items in "Numbers" can vary but if it changes in count the number of repetitions of names in "Names" column also has to change (in this example im using 3 random numbers which means each person is replicated 3 times). So in essence all items in "Numbers" needs to be repeated for all of the names in "Names" and both need to be variable from time to time as other things in the workbook change. I've looked through various forumns with no luck on how to replicate "numbers" for the items in "Names". Any help would be much appreciated.

NamesNumbersNamesNumbers
Bobby
Random1BobbyRandom1
JillRandom2BobbyRandom2
RandyRandom3BobbyRandom3
JillRandom1
JillRandom2
JillRandom3
RandyRandom1
RandyRandom2
RandyRandom3

<tbody>
</tbody>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the Board!

I'm not entirely sure of your requirements, but maybe:

ABCDEF
1NamesNumbersNamesNumbers
2BobbyRandom1BobbyRandom1
3JillRandom2BobbyRandom2
4RandyRandom3BobbyRandom3
5r4Bobbyr4
6JillRandom1
7JillRandom2
8JillRandom3
9Jillr4
10RandyRandom1
11RandyRandom2
12RandyRandom3
13Randyr4
14

<tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
D2=IF(ROWS($D$2:$D2)>COUNTA($A$2:$A$100)*COUNTA($B$2:$B$50),"",INDEX($A$2:$A$100,INT((ROWS($D$2:$D2)-1)/COUNTA($B$2:$B$100))+1))
E2=IF(D2="","",INDEX($B$2:$B$50,MOD(ROWS($D$2:$D2)-1,COUNTA($B$2:$B$50))+1))

<tbody>
</tbody>

<tbody>
</tbody>


Let us know if this is what you're looking for.
 
Upvote 0
I cant get that to work for me. Its just repeating the last item in the "numbers" range over and over again. Not sure what I'm doing wrong. Thanks for the help Eric W.

The formula converted to my sheet looks like this
=IF(A7="","",INDEX('Labor Only'!$A$2:$A$18,MOD(ROWS($A$7:$A40)-1,COUNTA('Labor Only'!$A$2:$A$18))+1))
 
Upvote 0
What cell does that formula go in?


Goes in the E1 cell in the example below. The intent is to duplicate the "numbers" the same number of times as the people are duplicated. If would be the same as using a macro to copy/paste "N" number of times, but of course a formula to do that would look much different.
 
Upvote 0
If the A and B columns are on a sheet named 'Labor Only', and you don't want the headers in D1:E1, then the formulas would look like:


DEF
1BobbyRandom1
2BobbyRandom2
3BobbyRandom3
4Bobbyr4
5JillRandom1
6JillRandom2
7JillRandom3
8Jillr4
9RandyRandom1
10RandyRandom2
11RandyRandom3
12Randyr4
13

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
D1=IF(ROWS($D$1:$D1)>COUNTA('Labor Only'!$A$2:$A$18)*COUNTA('Labor Only'!$B$2:$B$20),
"",INDEX('Labor Only'!$A$2:$A$18,INT((ROWS($D$1:$D1)-1)/COUNTA('Labor Only'!$B$2:$B$20))+1)
)
E1=IF(D1="","",INDEX('Labor Only'!$B$2:$B$20,MOD(ROWS($E$1:$E1)-1,COUNTA('Labor Only'!$B$2:$B$20))+1))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
If the A and B columns are on a sheet named 'Labor Only', and you don't want the headers in D1:E1, then the formulas would look like:


DEF
1BobbyRandom1
2BobbyRandom2
3BobbyRandom3
4Bobbyr4
5JillRandom1
6JillRandom2
7JillRandom3
8Jillr4
9RandyRandom1
10RandyRandom2
11RandyRandom3
12Randyr4
13

<tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
D1=IF(ROWS($D$1:$D1)>COUNTA('Labor Only'!$A$2:$A$18)*COUNTA('Labor Only'!$B$2:$B$20),
"",INDEX('Labor Only'!$A$2:$A$18,INT((ROWS($D$1:$D1)-1)/COUNTA('Labor Only'!$B$2:$B$20))+1)
)
E1=IF(D1="","",INDEX('Labor Only'!$B$2:$B$20,MOD(ROWS($E$1:$E1)-1,COUNTA('Labor Only'!$B$2:$B$20))+1))

<tbody>
</tbody>

<tbody>
</tbody>

Thanks for taking the time to help Eric W. This worked perfectly for me.
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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