Hi All,
I found the following code but want to modify it slightly but not sure where I am going wrong.
I basically just want the following to happen
1. Input box asking on what row should the insert start
2. How many rows to be inserted
Click ok
The code below has a bit about intervals, I ahve tried reworking it but keep coming up with errors, if anyone can help that would be great.
Sub inerrtrows()
Dim NumRowsToInsert, FirstRow As Long
Dim RowIncrement As Long
Dim ws As Excel.Worksheet
Dim LastRow As Long
Dim LastEvenlyDivisibleRow
Dim i As Long
Do
FirstRow = InputBox("Please indicate at which row you want to start.")
Loop Until IsNumeric(FirstRow) 'keeps on asking until they enter an actual number, otherwise the program will lose its mind when the user inputs a character
NumRowsToInsert = InputBox("How many rows would you like to insert between each row of data?") 'any number greater than 0
RowIncrement = InputBox("How many rows of data between line inserts?")
Set ws = ActiveSheet
With ws
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
LastEvenlyDivisibleRow = Int(LastRow / RowIncrement) * RowIncrement
If LastEvenlyDivisibleRow = 0 Then
Exit Sub
End If
Application.ScreenUpdating = False
For i = LastEvenlyDivisibleRow To FirstRow Step -RowIncrement
.Range(i & ":" & i + (NumRowsToInsert - 1)).Insert xlShiftDown
Next i
End With
Application.ScreenUpdating = True
End Sub
I found the following code but want to modify it slightly but not sure where I am going wrong.
I basically just want the following to happen
1. Input box asking on what row should the insert start
2. How many rows to be inserted
Click ok
The code below has a bit about intervals, I ahve tried reworking it but keep coming up with errors, if anyone can help that would be great.
Sub inerrtrows()
Dim NumRowsToInsert, FirstRow As Long
Dim RowIncrement As Long
Dim ws As Excel.Worksheet
Dim LastRow As Long
Dim LastEvenlyDivisibleRow
Dim i As Long
Do
FirstRow = InputBox("Please indicate at which row you want to start.")
Loop Until IsNumeric(FirstRow) 'keeps on asking until they enter an actual number, otherwise the program will lose its mind when the user inputs a character
NumRowsToInsert = InputBox("How many rows would you like to insert between each row of data?") 'any number greater than 0
RowIncrement = InputBox("How many rows of data between line inserts?")
Set ws = ActiveSheet
With ws
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
LastEvenlyDivisibleRow = Int(LastRow / RowIncrement) * RowIncrement
If LastEvenlyDivisibleRow = 0 Then
Exit Sub
End If
Application.ScreenUpdating = False
For i = LastEvenlyDivisibleRow To FirstRow Step -RowIncrement
.Range(i & ":" & i + (NumRowsToInsert - 1)).Insert xlShiftDown
Next i
End With
Application.ScreenUpdating = True
End Sub