George Philp
New Member
- Joined
- Nov 28, 2013
- Messages
- 5
Sub All()
'
' All Macro
'
' Keyboard Shortcut: Ctrl+z
'
Range("A6:Z23").Select
ActiveWorkbook.Worksheets("All").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("All").Sort.SortFields.Add Key:=Range("Z6:Z23"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("All").Sort.SortFields.Add Key:=Range("U6:U23"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("All").Sort
.SetRange Range("A6:Z23")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
This macro sorts data in a spreadsheet, and whilst the ‘top left’ value is fixed (A6, Z6, and U6) the bottom right value (Z23 and U23) is variable dependent on the number of rows in the spreadsheet. I do have a cell which is a count of the number of rows to sort (18 in this spreadsheet). Is there any way that I can code this in the macro to save me from editing the macro if rows are added/deleted? It would in effect be (for example) “Z” concatenated with “5 plus this cell value”.
'
' All Macro
'
' Keyboard Shortcut: Ctrl+z
'
Range("A6:Z23").Select
ActiveWorkbook.Worksheets("All").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("All").Sort.SortFields.Add Key:=Range("Z6:Z23"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("All").Sort.SortFields.Add Key:=Range("U6:U23"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("All").Sort
.SetRange Range("A6:Z23")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
This macro sorts data in a spreadsheet, and whilst the ‘top left’ value is fixed (A6, Z6, and U6) the bottom right value (Z23 and U23) is variable dependent on the number of rows in the spreadsheet. I do have a cell which is a count of the number of rows to sort (18 in this spreadsheet). Is there any way that I can code this in the macro to save me from editing the macro if rows are added/deleted? It would in effect be (for example) “Z” concatenated with “5 plus this cell value”.
Last edited: