Hi
I have this code sort the data in sheet file based on sheet RP as in orginal code works , but when change the range from A: C to A: D will gives error in this line
as in picture
what's the mistake guys
I have this code sort the data in sheet file based on sheet RP as in orginal code works , but when change the range from A: C to A: D will gives error in this line
VBA Code:
Application.AddCustomList ListArray:=CustSort
VBA Code:
Sub test()
Dim SortRng As Range, SortKey As Range
Dim SortRng2 As Range, SortKey2 As Range
Dim CustSort As Variant
Set SortRng = Sheets("file1").Range("A1:D" & Sheets("file1").Range("A" & Rows.Count).End(xlUp).Row)
Set SortKey = Sheets("file1").Range("B1")
CustSort = Sheets("RP").Range("B2:B" & Sheets("RP").Range("B" & Rows.Count).End(xlUp).Row).Value
Application.AddCustomList ListArray:=CustSort
SortRng.Sort Key1:=SortKey, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=Application.CustomListCount + 1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Application.DeleteCustomList Application.CustomListCount
End Sub