Hi All - I am using the below code to combine a few steps on a sheet. The last part of the macro, I am trying apply a sort on column B but I am getting strange results. Some of my data is at the top of the sheet and the rest is several thousand lines down with all blank data in between. Not sure where I am going wrong. If I do a manual sort, everything is just fine.
Code:
Public Const vbLightGreen As Long = 13434828
Sub ConditionalFormatDuplicates()
Sheets("Combined").Activate
Dim rg As Range
Dim uv As UniqueValues
'specify range to apply conditional formatting
Set rg = Range("A1:B50000")
'clear any existing conditional formatting
rg.FormatConditions.Delete
'identify duplicate values in range A2:A11
Set uv = rg.FormatConditions.AddUniqueValues
uv.DupeUnique = xlDuplicate
'apply conditional formatting to duplicate values
uv.Interior.Color = vbLightGreen
uv.Font.Color = vbBlack
uv.Font.Bold = True
'Aut-Fit Cells
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
Call DeleteRowWithContents
End Sub
Sub DeleteRowWithContents()
'Remove Rows containing...
With ActiveSheet
.AutoFilterMode = False
With Range("e1", Range("e" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Dedicated*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
'Sort Data
Dim LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("A1" & LastRow).Sort Key1:=Range("B1"), _
Order1:=xlDescending, Header:=xlNo
End Sub