Bobsta_666
New Member
- Joined
- Jan 15, 2024
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
Hello,
I have a macro that does what I need it to do but if there is a blank cell it deletes it also.
How do I add into this code a loop to ignore blanks? <>""
I have a macro that does what I need it to do but if there is a blank cell it deletes it also.
How do I add into this code a loop to ignore blanks? <>""
VBA Code:
Sub DeleteDuplicates()
Dim Rng As Range
Dim SRng As Range
Set Rng = Range("B3", Range("B3").End(xlDown).End(xlToRight))
rows("3:3").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("L2 Planning Sheet").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("L2 Planning Sheet").AutoFilter.Sort.SortFields.Add2 _
Key:=Range("K3"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("L2 Planning Sheet").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.AutoFilter
Range("J32").Select
Dim LastRow As Long
LastRow = Cells(rows.Count, 2).End(xlUp).row
Dim x As Long
For x = LastRow To 3 Step -1
If Cells(x, 12) = Cells(x - 1, 12) Then
rows(x).Delete
End If
Next x
End Sub