I have data in Cols A to C (headers are in row 1). I have tried to write code to sort the data in Col C based on a custom order on sheet "Unique" . These are listed in Z1 to Z5 on this sheet.
I get a run time error "Application-defined or object-defined error" and the code below is highlighted
It would be appreciated if someone could amend my code
See full Code below
I get a run time error "Application-defined or object-defined error" and the code below is highlighted
It would be appreciated if someone could amend my code
Code:
.Range("A1:C" & Lr).Sort Key1:=.Range("C1"), Order1:=xlAscending, _
customOrder:=customOrder, MatchCase:=False, Header:=xlYes
See full Code below
Code:
Sub Sort_Bank_Accounts()
Dim Lr As Long
Dim customOrderRange As Range
Dim customOrder() As Variant
' Set the custom order range
Set customOrderRange = Sheets("Unique").Range("Z1:Z5")
' Read the custom order values into an array
customOrder = customOrderRange.Value
With Sheets("Bank Accounts")
Lr = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A1:C" & Lr).Sort Key1:=.Range("C1"), Order1:=xlAscending, _
customOrder:=customOrder, MatchCase:=False, Header:=xlYes
End With
End Sub