Option Explicit
Sub Macro1()
Dim lngMyRow As Long
Application.ScreenUpdating = False
'Best to work backwards through the rows when inserting (or deleting) a row at a time like here.
For lngMyRow = Cells(Rows.Count, "C").End(xlUp).Row To 9 Step -1
If Range("C" & lngMyRow) <> Range("C" & lngMyRow - 1) Then
Rows(lngMyRow).EntireRow.Insert
End If
Next lngMyRow
Application.ScreenUpdating = True
End Sub
Give this macro a try...I would like the code to only insert a row between a change in years only, not a change in date.
[table="width: 500"]
[tr]
[td]Sub SeparateYearsByBlankRow()
Dim R As Long
For R = Cells(Rows.Count, "C").End(xlUp).Row To 2 Step -1
If Year(Cells(R, "C").Value) <> Year(Cells(R - 1, "C").Value) Then Rows(R).Insert
Next
End Sub[/td]
[/tr]
[/table]
Do your cells in Column C actually contain real Excel dates or are they only text that happen to look like dates? You can test if a cell contains a real date using the ISNUMBER function; for example,The code you have me is giving me a " run time error '13' " Type mismatch.
We just need to start the loop one row higher up than the last data cell then...Hi Rick,
The final row of my data set is not a date, it seems like the last row is what is throwing off the code you created. The last row in column "C" will always be empty. Do you know how to overcome this?
Sub SeparateYearsByBlankRow()
Dim R As Long
For R = Cells(Rows.Count, "C").End(xlUp).Row [B][COLOR="#FF0000"]- 1[/COLOR][/B] To 2 Step -1
If Year(Cells(R, "C").Value) <> Year(Cells(R - 1, "C").Value) Then Rows(R).Insert
Next
End Sub