SandsB
Well-known Member
- Joined
- Feb 13, 2007
- Messages
- 730
- Office Version
- 365
- Platform
- Windows
This code sorts my data based on the value in column B. But - one (or more) of the columns in my data is frequently empty and then the columns to the right of it aren't sorted. What changes could I make to ensure sorting by column B doesn't leave some columns unsorted?
VBA Code:
Sheets("Pending").Select
Range("B2").Select
ActiveWorkbook.Worksheets("Pending").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Pending").Sort.SortFields.Add2 Key:=Range( _
"B2:B10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Pending").Sort
.SetRange Range("B2:B10000")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Last edited by a moderator: