Create new rows based on cell value

jo15765

Well-known Member
Joined
Sep 23, 2011
Messages
591
I have an excel workbook where column G is going to list the total number of boxes, if that value is 1 no action is needed, if that number is greater than 1, I need to duplicate the data until the number of rows for that data = the total number of boxes, and increment the value in column E each row.

I'm sure this is confusing so I am attaching a sample workbook with my current format (described above) and once manipulated the desired format as a worksheet.

Thanks to all!

Seems I can't upload a workbook so here are images:

Current format:
1626472484253.png


Desired format:
1626472505202.png
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You can use XL2BB to post samples to the board so that we don't have to retype them (see link in my signature block below this reply).

Here's a way of doing what you want by using a helper column to keep a running total of the number of boxes in the source table (column E) with the output starting in column G. I've used a simplified example but it should be enough to give you an idea of how it works.

Book1
ABCDEFGHIJ
1idnamenumBoxesrun
2331a561331a56
3181b217331a56
464c818331a56
5331a56
6331a56
7331a56
8181b21
964c81
Sheet1
Cell Formulas
RangeFormula
E2:E4E2=SUM(D$1:D1,1)
G2:J9G2=IF(ROWS($G$2:$G2)>MAX($E$2:$E$4),"",INDEX($A$2:$D$4,MATCH(ROWS($G$2:$G2),$E$2:$E$4),0))
Dynamic array formulas.
 
Upvote 0
@jasonb75 - thanks for the help, very close to what I need. I've followed your signature to learn the xl2bb tool so I can provide usable sample data :)

This is what my source data looks like
sampledata.xlsx
ABCDEFGH
1saleidUserNamenum of itemsitem descriptionbox numberQFBtotal boxesmgr
2331pam1235socks146xya
3181zen1292mittens121aym
464mlb2028ovens121sua
Current Format


And this is how I need it formatted:
sampledata.xlsx
ABCDEFGH
1saleidUserNamenum of itemsitem descriptionbox numberQFBtotal boxesmgr
2331pam1235socks146xya
3331pam1235socks246xya
4331pam1235socks346xya
5331pam1235socks446xya
6331pam1235socks546xya
7331pam1235socks646xya
8181zen1292mittens121aym
964mlb2028ovens121sua
Desired Format


Only thing missing from the formula you provided (which is KILLER bc I didn't know you could do that in a formula) is the incremental column showing the box number :)
 
Upvote 0
I missed the box number when I looked at it before, it makes it a little more challenging but not impossible.

I've done this using dynamic arrays in office 365 but I think that it should work in older versions as well.
Book1
ABCDEFGHI
1saleidUserNamenum of itemsitem descriptionbox numberQFBtotal boxesmgrrt
2331pam1235socks146xya1
3181zen1292mittens121aym7
464mlb2028ovens121sua8
5
6saleidUserNamenum of itemsitem descriptionbox numberQFBtotal boxesmgr
7331pam1235socks146xya
8331pam1235socks246xya
9331pam1235socks346xya
10331pam1235socks446xya
11331pam1235socks546xya
12331pam1235socks646xya
13181zen1292mittens121aym
1464mlb2028ovens121sua
Sheet1
Cell Formulas
RangeFormula
I2:I4I2=SUM(G$1:G1,1)
E7:E14E7=IF(A7="","",IF(E6=G6,1,N(E6)+1))
F7:H14F7=IF(ROWS($A$7:$A7)>MAX($I$2:$I$4),"",INDEX($F$2:$H$4,MATCH(ROWS($A$7:$A7),$I$2:$I$4),0))
A7:D14A7=IF(ROWS($A$7:$A7)>MAX($I$2:$I$4),"",INDEX($A$2:$D$4,MATCH(ROWS($A$7:$A7),$I$2:$I$4),0))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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