VBA to Create Rows based on date differences

meshio123

New Member
Joined
Dec 6, 2007
Messages
9
Hi All,

Hopefully a very simple query - which maybe covered within the forum - yet can't find or pinpoint what the search criteria would be to locate it.

Simple four column spreadsheet all unique, the last three columns are start date, end date, variance (the other one is name)

I'd like a macro to create a row for each record for the number of days difference in the variance and include a date column for the unique day (if that makes sense) example below;


NAME | START DATE | END DATE | VARIANCE
Person 1 | 01/04/18 | 05/04/18 | 4

I'd like it to be
NAME | START DATE | END DATE | DATE | VARIANCE
Person 1 | 01/04/18 | 05/04/18 | 01/04/18 | 4
Person 1 | 01/04/18 | 05/04/18 | 02/04/18 | 4
Person 1 | 01/04/18 | 05/04/18 | 03/04/18 | 4
Person 1 | 01/04/18 | 05/04/18 | 04/04/18 | 4

is this even possible in excel? I'm guessing it is as I've seen some real amazing stuff happen

Thank you for your time in reading this and offering support - much appreciated!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Are you looking for it to update the current list where it currently resides (meaning it will need to add the DATE column to the current list), or do you want it to create a new list on a new sheet?
 
Upvote 0
How about
Code:
Sub AddRows()

   Dim i As Long
   Dim Qty As Long
      
   Columns(4).Insert
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      Qty = Range("E" & i).Value
      If Qty > 1 Then
         Rows(i + 1).Resize(Qty - 1).Insert
         Range("A" & i).Resize(Qty, 5).FillDown
         Range("D" & i).Value = Range("B" & i).Value
         Range("D" & i).AutoFill Range("D" & i).Resize(Qty), xlFillDays
      Else
         Range("D" & i).Value = Range("B" & i).Value
      End If
   Next i
         
End Sub
 
Upvote 0
How about
Code:
Sub AddRows()

   Dim i As Long
   Dim Qty As Long
      
   Columns(4).Insert
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      Qty = Range("E" & i).Value
      If Qty > 1 Then
         Rows(i + 1).Resize(Qty - 1).Insert
         Range("A" & i).Resize(Qty, 5).FillDown
         Range("D" & i).Value = Range("B" & i).Value
         Range("D" & i).AutoFill Range("D" & i).Resize(Qty), xlFillDays
      Else
         Range("D" & i).Value = Range("B" & i).Value
      End If
   Next i
         
End Sub

Thank you Joe and Fluff for your very quick responces!

Fluff - that works a treat! many thanks for this :)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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