Go to the VBA IDE (alt-F11), insert a new module, and paste in this code:
Public Sub InsertMonthlyRows()
Dim rngCurr As Excel.Range
Dim arrValues As Variant
Dim lngLastRow As Long
Dim lngCurrRow As Long
Dim intMonths As Integer
Set rngCurr = Worksheets("Sheet1").Range("A3")
lngLastRow = rngCurr.Parent.Columns(1).Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
LookAt:=xlPart, LookIn:=xlValues).Row
arrValues = rngCurr.Resize(lngLastRow - rngCurr.Row + 1, 13)
For lngCurrRow = UBound(arrValues) To LBound(arrValues) Step -1
If arrValues(lngCurrRow, 12) > 0 _
And arrValues(lngCurrRow, 13) > 0 Then
intMonths = Year(arrValues(lngCurrRow, 13)) + Month(arrValues(lngCurrRow, 13)) _
- Year(arrValues(lngCurrRow, 12)) - Month(arrValues(lngCurrRow, 12))
rngCurr.Offset(lngCurrRow, 1).Resize(intMonths, 1).EntireRow.Insert xlShiftDown
rngCurr.Offset(lngCurrRow - 1, 0).Resize(1, 1).EntireRow.Copy _
Destination:=rngCurr.Offset(lngCurrRow - 1, 0).Resize(intMonths + 1, 1).EntireRow
End If
Next lngCurrRow
Set rngCurr = Nothing
End Sub
You can call it with a command button or assign it to a ctrl-key combo. It starts at the bottom of the sheet, looking for entries with start and end dates. When it finds them, it calculates how many new rows are needed, inserts them, then copy/paste the source row to them. I'm not quite sure what you want to do with the entries at the bottom that don't have start and end dates, and you won't be able to run the macro more than once over the same data set.
The undated entries could be moved to a location lower in the sheet, if you want.
Bookmarks