I'm sure someone can help, I would like a macro to select every other row in a spreadsheet, and insert a row ahead of them. Any help would be greatly appreciated. I do not know a lot of VBA, but I'm trying to learn.
Insert Rows
-
-
-
Hi,
try the code
Code
Display MoreSub Insert_Rows() Dim i As Long, s, e s = InputBox("Starting Row") e = InputBox("Ending Row" & Chr(10) & Chr(10) & _ "must be equal or greater than Starting Row") Application.ScreenUpdating = False If (s = "") + (e = "") + (s > e) Then Exit Sub If (IsNumeric(s) = False) + (IsNumeric(e) = False) Then Exit Sub For i = s To e * 2 - s Step 2 Rows(i).Insert Next Application.ScreenUpdating = True End Sub
-
-
Here's a slightly different approach (actually two, because I wasn't sure if you wanted the final result to have alternating blank rows, or every third row blank.) The first produces alternating blank rows. The second every third row is blank.
Code
Display MoreSub InsertRows() Dim Lastrow As Long, r As Long Lastrow = Range("A65536").End(xlUp).Row For r = Lastrow To 2 Step -1 Rows(r).Insert Next r End Sub Sub InsertRows2() Dim Lastrow As Long, r As Long Lastrow = Range("A65536").End(xlUp).Row For r = Lastrow - 1 To 2 Step -2 Rows(r).Insert Next r End Sub
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!