Hi,
I use the below VBA to add columns to the right of a newly added cell...
when clicked it pauses for a second then completes is task as it should but then throw out an error 13 at this point... "If Not rng Is Nothing And Application.CountIf(rng, "") > 0 Then rng.Delete"
any ideas?
Private Sub CommandButton2_Click()
Dim rng As Range
Dim lastrow As Long
Dim startrow As Long
Dim i As Long
Application.ScreenUpdating = False
With ActiveSheet
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
startrow = 2
Do
For i = startrow To lastrow
If .Cells(i, "B").Value > .Cells(i, "C").Value Then
.Cells(i, "E").Resize(, 10).Insert shift:=xlDown
.Cells(i, "B").Insert shift:=xlDown
startrow = i + 1
Exit For
End If
Next i
Loop Until i > lastrow
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
Set rng = .Range("B2").Resize(lastrow - 1)
On Error Resume Next
Set rng = rng.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not rng Is Nothing And Application.CountIf(rng, "") > 0 Then rng.Delete shift:=xlUp
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Bookmarks