Hi Friends,
I am trying to add insert rows using macro.
L column fills with numbers. if L1 value is 5 then below need to insert 5 rows.
I tried below Macro.
But it getting Error.
Please solve this and let me know whats wrong in it
Sub InsertRowswork1()
Dim LastNumber As Long: LastNumber = ActiveSheet.Range("L" & Rows.Count).End(xlUp).Row
While LastNumber >= 2
If Not IsEmpty(ActiveSheet.Range("L" & LastNumber)) Then
Dim NewRows As Long: NewRows = ActiveSheet.Range("L" & LastNumber).Value
Dim InsertIndex As Long: InsertIndex = 1
While InsertIndex <= NewRows
ActiveSheet.Range("L" & LastNumber + 1).EntireRow.Insert
InsertIndex = InsertIndex + 1
Wend
End If
LastNumber = LastNumber - 1
Wend
End Sub
I am trying to add insert rows using macro.
L column fills with numbers. if L1 value is 5 then below need to insert 5 rows.
I tried below Macro.
But it getting Error.
Please solve this and let me know whats wrong in it
Sub InsertRowswork1()
Dim LastNumber As Long: LastNumber = ActiveSheet.Range("L" & Rows.Count).End(xlUp).Row
While LastNumber >= 2
If Not IsEmpty(ActiveSheet.Range("L" & LastNumber)) Then
Dim NewRows As Long: NewRows = ActiveSheet.Range("L" & LastNumber).Value
Dim InsertIndex As Long: InsertIndex = 1
While InsertIndex <= NewRows
ActiveSheet.Range("L" & LastNumber + 1).EntireRow.Insert
InsertIndex = InsertIndex + 1
Wend
End If
LastNumber = LastNumber - 1
Wend
End Sub