Kris,
In VBA this would look like
Public Sub SortHeaderRanges()
'#
'# declare private variables
'#
Dim lngMaxRow As Long
Dim lngRowNumber As Long
Dim strHeaderValue As String
'#
'# for the data on worksheet Sheet1
'#
With ThisWorkbook.Worksheets("Sheet1")
lngMaxRow = .Cells(.Rows.Count, "B").End(xlUp).Row
'#
'# duplicate header values
'#
For lngRowNumber = 1 To lngMaxRow
If LenB(.Cells(lngRowNumber, "A").Value & "") > 0 Then
strHeaderValue = .Cells(lngRowNumber, "A").Value
Else
.Cells(lngRowNumber, "A").Value = strHeaderValue
End If
Next lngRowNumber
'#
'# sort the entire range
'#
With .Sort
.SortFields.Clear
.SortFields.Add Key:=Cells(1, "A").Resize(lngMaxRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Cells(1, "A").Resize(lngMaxRow, 4)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'#
'# remove the header values that were introduced in step 1 for sorting purposes
'#
For lngRowNumber = 1 To lngMaxRow
If LenB(.Cells(lngRowNumber, "B").Value & "") > 0 Then
.Cells(lngRowNumber, "A").Value = vbNullString
End If
Next lngRowNumber
End With
End Sub
Bookmarks