AddCustomlist failed error

Maze123

New Member
Joined
Aug 3, 2020
Messages
5
Office Version
  1. 365
Hi,

What is preventing the below custom sort from running?

VBA Code:
Dim keyRange As Variant
Dim sortNum As Long
Dim RowsSorted As Long: RowsSorted = Worksheets("[tab]").Cells(Worksheets("[tab]").Rows.Count, 5).End(xlUp).Row
Worksheets("[tab]").Range("A2:A" & RowsSorted).NumberFormat = "@"

keyRange = ActiveWorkbook.Worksheets("[tab]").Cells.Range("A2:A" & RowsSorted).Value
    
Application.AddCustomList ListArray:=keyRange
sortNum = Application.CustomListCount
    
ActiveWorkbook.Worksheets("[LEFT][SIZE=4][FONT=Segoe UI][COLOR=rgb(20, 20, 20)][tab][/COLOR][/FONT][/SIZE][/LEFT]").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("[LEFT][SIZE=4][FONT=Segoe UI][COLOR=rgb(20, 20, 20)][tab][/COLOR][/FONT][/SIZE][/LEFT]").Sort.SortFields.Add Key:=Range("G:K"), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:=sortNum, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("[LEFT][SIZE=4][FONT=Segoe UI][COLOR=rgb(20, 20, 20)][tab][/COLOR][/FONT][/SIZE][/LEFT]").Sort
.SetRange Range("A:K")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

To satisfy object requirements, line 4 converts cells to text values yet the error persists. Otherwise the code looks fine to me but documentation/threads have not identified the cause of the error in this case.
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Watch MrExcel Video

Forum statistics

Threads
1,123,330
Messages
5,601,000
Members
414,419
Latest member
JRDunya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top