I get the error msg: "...sort reference not valid..."
and the ".Apply" line is highlighted. I am simply trying to select all cells
containg data and sort them by column A (5 columns are a constant):
and the ".Apply" line is highlighted. I am simply trying to select all cells
containg data and sort them by column A (5 columns are a constant):
Code:
Dim LastDataRow
LastDataRow = Range("C" & Rows.Count).End(xlUp).Row
Range("A2:G" & LastDataRow).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A2:G" & LastDataRow) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A2:G" & LastDataRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With