Hello,
I need assistance adjusting a macro. I need to sort one value alphabetically, then another value chronologically.
For example, I need
Jon Smith 10/9/2018
Jane Smith 10/31/2018
Jon Smith 9/30/2018
to become
Jane Smith 10/31/2018
Jon Smith 9/30/2018
Jon Smith 10/9/2018
I cant figure out how to define my second set within the same macro. In the below code, C4 and below are my alpha records, D4 and below (which is what I am trying to build into my code) would be my chronological records.
Thank you for your help in advance!
Sub NameSort()
'
' NameSort Macro
'
'
Dim DataFirstCell
Dim DataLastCell
Dim SortCellStart
Dim SortCellEnd
Range("B3").Select
DataFirstCell = ActiveCell.Address
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 4).Select
DataLastCell = ActiveCell.Address
Range("C4").
SortCellStart = ActiveCell.Address
Selection.End(xlDown).Select
SortCellEnd = ActiveCell.Address
ActiveWorkbook.Worksheets("Sorted Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sorted Data").Sort.SortFields.Add Key:=Range(SortCellStart & ":" & SortCellEnd), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sorted Data").Sort
.SetRange Range(DataFirstCell & ":" & DataLastCell)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("B3").Select
End Sub
I need assistance adjusting a macro. I need to sort one value alphabetically, then another value chronologically.
For example, I need
Jon Smith 10/9/2018
Jane Smith 10/31/2018
Jon Smith 9/30/2018
to become
Jane Smith 10/31/2018
Jon Smith 9/30/2018
Jon Smith 10/9/2018
I cant figure out how to define my second set within the same macro. In the below code, C4 and below are my alpha records, D4 and below (which is what I am trying to build into my code) would be my chronological records.
Thank you for your help in advance!
Sub NameSort()
'
' NameSort Macro
'
'
Dim DataFirstCell
Dim DataLastCell
Dim SortCellStart
Dim SortCellEnd
Range("B3").Select
DataFirstCell = ActiveCell.Address
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 4).Select
DataLastCell = ActiveCell.Address
Range("C4").
SortCellStart = ActiveCell.Address
Selection.End(xlDown).Select
SortCellEnd = ActiveCell.Address
ActiveWorkbook.Worksheets("Sorted Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sorted Data").Sort.SortFields.Add Key:=Range(SortCellStart & ":" & SortCellEnd), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sorted Data").Sort
.SetRange Range(DataFirstCell & ":" & DataLastCell)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("B3").Select
End Sub