Hello all,
I have created a custom sorting macro for one sheet on my workbook. The macro works great when i'm on that sheet. My problem is that i want to use the macro to run when being called from a different sheet. Here is the code i'm using:
What do i need to do in order to allow me to use the above code when it is being called on a macro from a different active sheet?
I have created a custom sorting macro for one sheet on my workbook. The macro works great when i'm on that sheet. My problem is that i want to use the macro to run when being called from a different sheet. Here is the code i'm using:
Code:
Dim TPws As Worksheet
Dim lrow As Long
Set TPws = ThisWorkbook.Worksheets("Tract Parcels")
lrow = TPws.Cells(Rows.Count, 7).End(xlUp).Row
TPws.Range("A2" & ":AW" & lrow).Select
ActiveWorkbook.Worksheets("Tract Parcels").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Tract Parcels").Sort.SortFields.Add Key:=Range("G2" & ":G" & lrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Tract Parcels").Sort.SortFields.Add Key:=Range("H2" & ":H" & lrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Tract Parcels").Sort
.SetRange Range("A2" & ":AW" & lrow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
What do i need to do in order to allow me to use the above code when it is being called on a macro from a different active sheet?