Generating 36 rows from date range

Marcy

New Member
Joined
Aug 14, 2006
Messages
14
I built a power automate model to load data from pdf contracts to an excel table. The contract will have a term anywhere from 3 months to 3 years with individual data points for Start date and end date. I would like a way to generate a data set where my product is within 2 of the 6 products. I then want to translate that one row per product into 12 rows with cycle start and end dates representing the months. I would like this to happen automatically or with a refresh when the data loads. Like so:
Input
ProductStart DateEnd Date
Widgets01/01/2312/31/25
Flippers03/01/2405/31/24

Output (dates shown as needed for upload)
ProductCycle StartCycle End
Widgets010123013123
Widgets020123022823
Widgets030123033123
.........
Widgets120125123125
Flippers030124033124
Flippers040124043024
Flippers050124053124

I don't have VBA skills.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
paste the code below into a module,
start on the sheet with the widgets,
run run macro: BuildList

Code:
Sub BuildList()
Dim vProd, vStartDte, vEndDte
Dim vDate As Date, vEoM As Date
Dim wsSrc As Worksheet, wsTarg As Worksheet

Set wsSrc = ActiveSheet
Sheets.Add
Set wsTarg = ActiveSheet
ActiveSheet.Name = "results"

wsSrc.Activate
Range("A2").Select
While ActiveCell.Value <> ""
     vProd = ActiveCell.Value
     vStartDte = ActiveCell.Offset(0, 1).Value
     vEndDte = ActiveCell.Offset(0, 2).Value
    
    wsTarg.Activate
    vDate = vStartDte
    vEoM = DateAdd("d", -1, DateAdd("m", 1, vDate))
    
    While vDate <= vEndDte
       ActiveCell.Offset(0, 0).Value = vProd
       ActiveCell.Offset(0, 1).Value = Format(vDate, "mmddyy")
       ActiveCell.Offset(0, 2).Value = Format(vEoM, "mmddyy")
       
       vDate = DateAdd("m", 1, vDate)
       vEoM = DateAdd("d", -1, DateAdd("m", 1, vDate))
        ActiveCell.Offset(1, 0).Select  'next row
    Wend
       
      'next product
    wsSrc.Activate
    ActiveCell.Offset(1, 0).Select  'next row
Wend

Set wsSrc = Nothing
Set wsTarg = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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