I have a vba code that automatically sorts my table in descending sales order based on column P. However when it sorts it brings all the blank fields to the top....How can i modify the code where it ignores blank rows and sorts in descending order for fields with values.
All the cells including blank ones has formulas in them so i dont want to delete them.
Thanks
All the cells including blank ones has formulas in them so i dont want to delete them.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Range("N22:S22").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("POS Tracker").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("POS Tracker").Sort.SortFields.Add Key:=Range( _
"P23:P69"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("POS Tracker").Sort
.SetRange Range("N22:S69")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Thanks
Last edited: