I have recorded a macro to sort my worksheet in a specific order and I get the following VBA.
Cells.Select
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Add Key:=Range( _
"A2:A10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Add Key:=Range( _
"G2:G10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Add Key:=Range( _
"L2:L10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("DReg").Sort
.SetRange Range("A1:AB10")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
If I add another row to the sheet beyond row 10 or another column beyond AB then the new data is not picked up by the sort macro. Is there a way to select the whole sheet to be covered by the sort?
Cheers
Cells.Select
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Add Key:=Range( _
"A2:A10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Add Key:=Range( _
"G2:G10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("DReg").Sort.SortFields.Add Key:=Range( _
"L2:L10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("DReg").Sort
.SetRange Range("A1:AB10")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
If I add another row to the sheet beyond row 10 or another column beyond AB then the new data is not picked up by the sort macro. Is there a way to select the whole sheet to be covered by the sort?
Cheers