I have this Subroutine that works, but I have recently started updating the sheet and adding new columns. I'm finding updating the current macro to be a bit of a chore.
Is there a way to use named ranges instead of declaring the cell ranges as in this code?
Private Sub Reset_Rows_Click()
Const USED_RANGE As String = "A2:FI5002"
Const BLANKS_COLS As String = "A2:A5002,B2:B5002,F2:G5002,K2:K5002,M2:O5002,V2:Y5002,AA2:AB5002,AE2:AM5002,AU2:AW5002,AY2:AY5002,BA2:BD5002,BG2:BL5002,BN2:BU5002,CL2:CO5002,CX2:CX5002,DF2:FI5002"
Const SELECT_COLS As String = "H2:I5002,J2:J5002,P2:U5002,Z2:Z5002,AC2:AD5002,AN2:AT5002,AX2:AX5002,AZ2:AZ5002,BE2:BF5002"
Const NA_COLS As String = "E2:E5002"
Const BLANKS_VAL As String = vbNullString
Const SELECTS_VAL As String = " --Select--"
Const NA_VAL As String = "N/A"
Dim ws As Worksheet, ur As Range
Set ws = ActiveSheet
Set ur = ws.Range(USED_RANGE)
Application.ScreenUpdating = False
With ur
.AutoFilter Field:=1, Criteria1:="="
If .SpecialCells(xlCellTypeVisible).Count > 1 Then
.Range(BLANKS_COLS).Value2 = BLANKS_VAL
.Range(SELECT_COLS).Value2 = SELECTS_VAL
.Range(NA_COLS).Value2 = NA_VAL
End If
.AutoFilter
End With
'ws.Cells(5003, 1).EntireRow.Delete
'Sort
Range("A3:FS5002").Select
ActiveWorkbook.Worksheets("Master").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Master").Sort.SortFields.Add Key:=Range( _
"E3:E5002"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Master").Sort.SortFields.Add Key:=Range( _
"L3:L5002"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Master").Sort.SortFields.Add Key:=Range( _
"A3:A5002"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Master").Sort
.SetRange Range("A3:FS5002")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
End Sub
Const BLANK_COLS As String = "BlankRange"
but it didn't work. Can you assist with what I am doing wrong? \$\endgroup\$