K
Ken Wright
Probably kinda kludgy because I loop the code each time to insert the number of rows you want -
Won't impact time too much unless you are thinking of adding thousands of rows, but I have no
doubt one of the VBA gurus will point out how I can speed it up. The routine prompts you for a
number of rows, but on the assumption that most of the time you will just want a single row,
leaving the response blank will give a single row, rather than having to type in a number. The
dialog box will prompt you anyway.
Sub ExtendRange2()
Dim lrow As Long
Dim lrow1 As Long
Dim lrow2 As Long
ans = InputBox("How many rows do you want to insert?" & vbCrLf _
& "Leave blank & Hit OK for just 1 row")
If ans = "" Then
ans = 1
End If
Application.ScreenUpdating = False
For x = 1 To ans
lrow = Cells(Rows.Count, "A").End(xlUp).Row
lrow1 = lrow - 1
lrow2 = lrow - 2
Rows(lrow1).Insert Shift:=xlDown
Range("A" & lrow2, "AO" & lrow2).AutoFill _
Destination:=Range("A" & lrow2, "AO" & lrow1), Type:=xlFillDefault
On Error Resume Next
Range("A" & lrow1, "AO" & lrow1).SpecialCells(xlCellTypeConstants, 23).ClearContents
Next x
Application.ScreenUpdating = True
End Sub
Won't impact time too much unless you are thinking of adding thousands of rows, but I have no
doubt one of the VBA gurus will point out how I can speed it up. The routine prompts you for a
number of rows, but on the assumption that most of the time you will just want a single row,
leaving the response blank will give a single row, rather than having to type in a number. The
dialog box will prompt you anyway.
Sub ExtendRange2()
Dim lrow As Long
Dim lrow1 As Long
Dim lrow2 As Long
ans = InputBox("How many rows do you want to insert?" & vbCrLf _
& "Leave blank & Hit OK for just 1 row")
If ans = "" Then
ans = 1
End If
Application.ScreenUpdating = False
For x = 1 To ans
lrow = Cells(Rows.Count, "A").End(xlUp).Row
lrow1 = lrow - 1
lrow2 = lrow - 2
Rows(lrow1).Insert Shift:=xlDown
Range("A" & lrow2, "AO" & lrow2).AutoFill _
Destination:=Range("A" & lrow2, "AO" & lrow1), Type:=xlFillDefault
On Error Resume Next
Range("A" & lrow1, "AO" & lrow1).SpecialCells(xlCellTypeConstants, 23).ClearContents
Next x
Application.ScreenUpdating = True
End Sub