How to create a specified number of rows for each date?

alexcr

Board Regular
Joined
Oct 15, 2018
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Let's say that in Cells A1-A7 there are seven dates, and in Cells B1-B7 there are the number of rows you'd like per date.

From A9 downward, you'd like to list each date the number of times specified. For example...

• If Cell A1 contains "7/12/21" and Cell B1 contains "3", then Cells A9-A11 would all be "7/12/21".

• If Cell A2 contains "7/15/21" and Cell B2 contains "2", then Cells A12-A13 would all be "7/15/21".

• If Cell A3 contains "7/18/21" and Cell B3 contains "0", then this date would be skipped.

• And so on.

Is there a formula or formulas that can automatically generate these cells/rows? Thanks in advance!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Place this formula in cell A9 and copy it down the number of rows that SUM(B1:B7) produces

Excel Formula:
=IFS(ROW()-8<=$B$1,$A$1,ROW()-(8+$B$1)<=$B$2,$A$2,ROW()-(8+SUM($B$1:$B$2))<=$B$3,$A$3,ROW()-(8+SUM($B$1:$B$3))<=$B$4,$A$4,ROW()-(8+SUM($B$1:$B$4))<=$B$5,$A$5,ROW()-(8+SUM($B$1:$B$5))<=$B$6,$A$6,ROW()-(8+SUM($B$1:$B$6))<=$B$7,$A$7,TRUE,"")
 
Upvote 0
Place this formula in cell A9 and copy it down the number of rows that SUM(B1:B7) produces

Excel Formula:
=IFS(ROW()-8<=$B$1,$A$1,ROW()-(8+$B$1)<=$B$2,$A$2,ROW()-(8+SUM($B$1:$B$2))<=$B$3,$A$3,ROW()-(8+SUM($B$1:$B$3))<=$B$4,$A$4,ROW()-(8+SUM($B$1:$B$4))<=$B$5,$A$5,ROW()-(8+SUM($B$1:$B$5))<=$B$6,$A$6,ROW()-(8+SUM($B$1:$B$6))<=$B$7,$A$7,TRUE,"")

Thanks, @Crystalyzer. But is there any way to do this dynamically so that I don't have to (figure out how many rows are needed and then) copy and paste the formula?
 
Upvote 0
Here is a way using Power Query.

Book1
AB
1DateX
27/12/20212
37/13/20210
47/14/20215
57/15/20217
67/16/20212
77/17/20214
87/18/20214
9
10Date
117/12/2021
127/12/2021
137/14/2021
147/14/2021
157/14/2021
167/14/2021
177/14/2021
187/15/2021
197/15/2021
207/15/2021
217/15/2021
227/15/2021
237/15/2021
247/15/2021
257/16/2021
267/16/2021
277/17/2021
287/17/2021
297/17/2021
307/17/2021
317/18/2021
327/18/2021
337/18/2021
347/18/2021
Sheet4


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Rows = Table.TransformColumns(Source,{{"X", each {1.._}}}),
    Expand = Table.ExpandListColumn(Rows, "X"),
    noNull = Table.SelectRows(Expand, each ([X] <> null)),
    RC = Table.RemoveColumns(noNull,{"X"}),
    toDate = Table.TransformColumnTypes(RC,{{"Date", type date}})
in
    toDate

And here is a way using formulas.

Book1
AB
17/12/20212
27/13/20210
37/14/20215
47/15/20217
57/16/20212
67/17/20214
77/18/20214
8
97/12/2021
107/12/2021
117/14/2021
127/14/2021
137/14/2021
147/14/2021
157/14/2021
167/15/2021
177/15/2021
187/15/2021
197/15/2021
207/15/2021
217/15/2021
227/15/2021
237/16/2021
247/16/2021
257/17/2021
267/17/2021
277/17/2021
287/17/2021
297/18/2021
307/18/2021
317/18/2021
327/18/2021
Sheet5
Cell Formulas
RangeFormula
A9:A32A9=LET(d,A1:A7,s,SUBSTITUTE(TEXTJOIN(",",1,REPT(ROW(d)&",",B1:B7)),",,",","),se,LEFT(s,LEN(s)-1),f,FILTERXML("<x><y>" & SUBSTITUTE(se,",","</y><y>") & "</y></x>","//y"),INDEX(d,f))
Dynamic array formulas.
 
Upvote 0
Another way using VBA.
Book1
AB
17/12/20213
27/15/20212
37/18/20210
47/21/20211
57/24/20212
67/27/20213
77/30/20214
8
97/12/2021
107/12/2021
117/12/2021
127/15/2021
137/15/2021
147/21/2021
157/24/2021
167/24/2021
177/27/2021
187/27/2021
197/27/2021
207/30/2021
217/30/2021
227/30/2021
237/30/2021
Sheet1

VBA Code:
Sub RowsPerDate()
'assumes input dates begin in A1
Dim Rin As Range, NxRw As Long, c As Range
Set Rin = Range("A1").CurrentRegion
NxRw = Rin.Columns(1).Cells.Count + 2
Application.ScreenUpdating = False
For Each c In Rin.Columns(1).Cells
If c.Offset(0, 1).Value > 0 Then
    Cells(NxRw, 1).Resize(c.Offset(0, 1).Value, 1).Value = c.Value
    NxRw = Cells(Rows.Count, "A").End(xlUp).Row + 1
End If
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you, @lrobbo314! This dynamic array formula works perfectly.

And thanks to everyone else who responded, too.

@lrobbo314 The only issue I'm having is figuring out how the dynamic array formula should be adjusted if the A1:B7 range starts on a different row and/or a different column, i.e. not from A1 by from, say, B19.

I've adjusted the formula so that it's still referencing those two columns, in their new location. But the formula nevertheless seems to be broken.
 
Upvote 0
Needed to add a bit to the formula to make it work on any row. I highlighted the change in the formula below.

Book1
EFG
107/12/20212
117/13/20210
127/14/20215
137/15/20217
147/16/20212
157/17/20214
167/18/20214
17
18
19
207/12/2021
217/12/2021
227/14/2021
237/14/2021
247/14/2021
257/14/2021
267/14/2021
277/15/2021
287/15/2021
297/15/2021
307/15/2021
317/15/2021
327/15/2021
337/15/2021
347/16/2021
357/16/2021
367/17/2021
377/17/2021
387/17/2021
397/17/2021
407/18/2021
417/18/2021
427/18/2021
437/18/2021
Sheet1
Cell Formulas
RangeFormula
G20:G43G20=LET(d,E10:E16,s,SUBSTITUTE(TEXTJOIN(",",1,REPT(ROW(d)-ROW(E10)+1&",",F10:F16)),",,",","),se,LEFT(s,LEN(s)-1),f,FILTERXML("<x><y>" & SUBSTITUTE(se,",","</y><y>") & "</y></x>","//y"),INDEX(d,f))
Dynamic array formulas.
 
Upvote 0
@lrobbo314, this suddenly isn't working, and I can't figure out why. Do you see anything that looks off to you...?

Screen Shot 2021-07-19 at 12.09.02 AM.png
 
Upvote 0

Forum statistics

Threads
1,214,670
Messages
6,120,830
Members
448,990
Latest member
rohitsomani

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