Hi,
I am working on a macro in which constantly gets updated with new columns each quarter and new rows each quarter. To avoid having to update the macro every few months to reflect the new rows and columns, I would like to edit the sort button to go to the end of the columns (all have headers) and to the bottom of row of data (sort criteria always has data in cell). My current code is below. Can anyone help?
Range F = The column I need to sort the worksheet by in ascending order. 5000 is just a estimated number to hold us over until I can get the correct coding to work.
Range A - BL = Current start and finish of columns. But a few columns have been or will be added shortly.
ActiveWorkbook.Worksheets("Master List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Master List").Sort.SortFields.Add Key:=Range("F4:F5000") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Master List").Sort
.SetRange Range("A3:BL5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
I appreciate anyone who can give me tips.
I am working on a macro in which constantly gets updated with new columns each quarter and new rows each quarter. To avoid having to update the macro every few months to reflect the new rows and columns, I would like to edit the sort button to go to the end of the columns (all have headers) and to the bottom of row of data (sort criteria always has data in cell). My current code is below. Can anyone help?
Range F = The column I need to sort the worksheet by in ascending order. 5000 is just a estimated number to hold us over until I can get the correct coding to work.
Range A - BL = Current start and finish of columns. But a few columns have been or will be added shortly.
ActiveWorkbook.Worksheets("Master List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Master List").Sort.SortFields.Add Key:=Range("F4:F5000") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Master List").Sort
.SetRange Range("A3:BL5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
I appreciate anyone who can give me tips.
