kmmsquared
New Member
- Joined
- Jan 7, 2011
- Messages
- 33
Hi!
I am running into a problem with my code below. When Range("AB2:AB" & lngLastRow) is nothing, Column AB doesn't delete. How should I fix this? Thanks!
I am running into a problem with my code below. When Range("AB2:AB" & lngLastRow) is nothing, Column AB doesn't delete. How should I fix this? Thanks!
Code:
Sub Check()
Dim lngLastRow As Long
With Sheets("B")
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set Check = Range("AB2:AB" & lngLastRow)
Columns("AB:AB").Copy
Columns("AB:AB").PasteSpecial Paste:=xlPasteValues
Columns("AB:AB").AutoFilter Field:=1, Criteria1:="=UD", Operator:=xlOr, Criteria2:="="
If Not Check Is Nothing Then Check.SpecialCells(xlCellTypeVisible).ClearContents
Columns("AB:AB").AutoFilter
[COLOR=red]If Check Is Nothing Then
[/COLOR][COLOR=red]Columns("AB:AB").Delete[/COLOR]
[COLOR=red]Else
[/COLOR] Columns("AB:AB").AutoFilter Field:=1, Criteria1:="<>"
On Error Resume Next
Range("AB2:AB" & lngLastRow).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 22
Columns("AB:AB").AutoFilter
End If
End With
End Sub