neRoc
Below probably another solution
Public Sub InsertBlancRows()
Application.ScreenUpdating = False 'Speeds up Application.Calculation = xlCalculationManual 'Speeds up: if there are many formulas
'Declaring Variables Dim Idx As Long 'row counter in selection Dim cIdx As Long 'Col.nr in selection Dim Max As Long ' Dim ShMax As Long ShMax = ActiveCell.SpecialCells(xlLastCell).Row
With Selection Max = .Rows.Count For Idx = 2 To Max If .Cells(Idx, cIdx) <> "" Then 'Only non-blanc cells in the first column If ShMax > .Cells(Idx, cIdx).Row + Max - Idx Then 'Controling max sheet size If .Cells(Idx - 1, cIdx) <> "" And .Cells(Idx, cIdx) <> .Cells(-1 + Idx, cIdx) Then .Cells(Idx, cIdx).EntireRow.Insert 'Extra Upgrading the counter and limit Max = Max + 1 Idx = Idx + 1 End If Else MsgBox "Function aborted:" & Chr(10) & "Maximum rows exceeded" Idx = Max 'Next loop will not be executed End If End If Next End With Application.Calculation = xlCalculationAutomatic Selection.Cells(1, cIdx).Resize(Max, Selection.Columns.Count).Select 'New selection End Sub
Kind regards & Suc6
FiftyFive
|