create duplicate rows of records based on criteria

mollys

New Member
Joined
Oct 14, 2009
Messages
14
In one worksheet I have rows of data that represent stats for a particular date range:

Start - End - #Days - Role - Hours
1/1 - 1/17 - 17 - Polly - 46
1/3 - 1/10 - 8 - John - 17


I would like to create a new work sheet that shows a daily breakdown

Start - Role - Hours
1/1 - Polly - 2.7
1/2 - Polly - 2.7
1/3 - Polly - 2.7
etc...


I don't even need something to automatically do the averages, because I can do that with a formula. I would just like to know how to automatically create the correct number of rows for each role depending on the number of days within the date range.

Anyone?
Thanks!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
below is some vba code. hold alt+f11, insert a new module (insert module on the menu bar), paste the below code, close the vba ide. Hold alt+f8 to run the macro 'BreakOut'. Note, this will copy data from Sheet1 and paste the breakout to Sheet2.

Code:
Sub BreakOut()
Dim LastRow As Long, i As Long
Dim StartDt As Date
Dim EndDt As Date
Dim myName As String
Dim myHours As Variant
Dim pr As Long

LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
pr = 2
 
With Sheets("Sheet2")
    .Range("A1") = "Start"
    .Range("B1") = "Role"
    .Range("C1") = "Hours"
End With
 
For i = 2 To LastRow
 
StartDt = Sheets("Sheet1").Range("A" & i)
EndDt = Sheets("Sheet1").Range("B" & i)
myName = Sheets("Sheet1").Range("D" & i)
myHours = Sheets("Sheet1").Range("E" & i) / Sheets("Sheet1").Range("C" & i)
    
   Do Until StartDt > EndDt
        
        With Sheets("Sheet2")
            .Range("A" & pr) = StartDt
            .Range("B" & pr) = myName
            .Range("C" & pr) = myHours
        End With
        
    StartDt = StartDt + 1
    
    pr = pr + 1
    
    Loop
    
Next
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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