ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert blank row (https://www.excelbanter.com/excel-programming/289403-insert-blank-row.html)

Annette[_3_]

Insert blank row
 
Does anyone have a macro already written that inserts a blank row above any
date found in a column. I am attempting to insert a blank row above every
date found in column A -- the number of rows will always be different.

Thanks.



Dave Peterson[_3_]

Insert blank row
 
I think that this one will work.

Option Explicit
Sub testme()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
If IsDate(.Cells(iRow, "A").Value) Then
.Rows(iRow).Insert
End If
Next iRow
End With

End Sub

The last one worked ok--unless there were two dates in consecutive cells.

(Bad testing on my part--sorry.)

Annette wrote:

Does anyone have a macro already written that inserts a blank row above any
date found in a column. I am attempting to insert a blank row above every
date found in column A -- the number of rows will always be different.

Thanks.


--

Dave Peterson



All times are GMT +1. The time now is 08:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com