Add Row Above Date

AdamDN

New Member
Joined
Sep 22, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I am working on schedules and want to add blank rows to each schedule for any changes that need to be annotated. So I want to add 2 blank rows above any date that I find (except the first date because we're not scheduling for the past)). I have typed and retyped 5 or 6 different ways and I am puzzled. Here is what I have, but it keeps adding ~130 rows after the second date and will not add rows above any other date. Also, I would like to delete the two rows that auto-generate below each date (haven't worked on that one yet because I can't even get this far)>

Sub InsertRowsAboveDate()

With Range("A:A")

Dim LR As Long
Dim r As Long

LR = Cells(Rows.Count, "A").End(xlUp).Row

For r = 2 To LR
If IsDate(Cells(r, "A")) Then
Rows(r).Insert
End If

Next r

End With

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try to loop from bottom to top. Not knowing how your data looks like:

VBA Code:
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR to 2 step - 1
  If IsDate(Cells(r, "A")) Then  Rows(r).Insert xldown
Next
 
Upvote 0
Solution
Try to loop from bottom to top. Not knowing how your data looks like:

VBA Code:
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR to 2 step - 1
  If IsDate(Cells(r, "A")) Then  Rows(r).Insert xldown
Next
Right on man! Works perfect. Just have to work on deleting the rows beneath. I'll reach out if I have trouble. Thank you again.
 
Upvote 0

Forum statistics

Threads
1,215,851
Messages
6,127,291
Members
449,374
Latest member
analystvar

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