The following macro sorts columns A - F based on values in Columns B and D.
I plan to use similar macros for other tabs in the same spreadsheet.
The first row for each tab will be different and will vary as existing rows are deleted and/or new rows are added.
I would like to have the references to A23, B23, D23 and F23 be variables.
This will allow the values to be placed in a cell on each tab.
Having the value in a cell will:
Allow for changes to that value as changes are made to rows on the tab
Eliminate the need to change the macro as changes are made to rows on the tab
Thank you.
Code
Sub BudgetPendingSort()
'
'
' Sort Pending Debit Tab - Other Transactions
'
ActiveWorkbook.Worksheets("Pending Debit").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Pending Debit").Sort.SortFields.Add2 _
Key:=Range("B23", Range("B23").End(xlDown)), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Pending Debit").Sort.SortFields.Add2 _
Key:=Range("D23", Range("D23").End(xlDown)), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Pending Debit").Sort
.SetRange Range("A23", Range("F23").End(xlDown))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Pending Debit").Select
ActiveWorkbook.Worksheets("Pending Debit").Range("B23").End(xlDown).Offset(1, 0).Select
End Sub
Display More