Office Script - getSort() for a custom list

Mike1402

New Member
Joined
Jun 16, 2011
Messages
9
Hi I've been trying to put together a script which will sort a named range in the active worksheet. I chose script over VBA as the script can easily be used in many workbooks which have the same layout and named range, and are used by multiple people, but I'm happy to take advise if there is a better way ...

I have the following code:

JavaScript:
function main(workbook: ExcelScript.Workbook) {

    let selectedSheet = workbook.getActiveWorksheet();

    //Define the range
    const priceRange = selectedSheet.getRange("MainTable");

    //Define custom lists to sort on for each custom column
    const customSpeed = ["H", "V", "W", "Y", "(Y)", "Z"];


    priceRange.getSort().apply([
        {
            key: 1,
            ascending: true,
            sortOn: ExcelScript.SortOn.value,
            customPattern
        }
    ], false);
}

I've had a few different iterations of the last part of the above code, none of it works as it doesn't appear to be part of the 'SortField'. I've tried looking through the Microsoft API reference, tried searching ... even tried using ChatGPT! There doesn't appear to be much help with this that I could find. Any ideas? Should I just do it differently? I wanted to avoid making the workbook a macro enabled book.

I can successfully sort using the above code without the sortOn custom list attempt, just regular ascend or descend.

Thanks.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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
Back
Top