How to Create a Loop to ignore BLANK CELLS

Bobsta_666

New Member
Joined
Jan 15, 2024
Messages
14
Office Version
  1. 365
Platform
  1. 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? <>""

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
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top