Userform listbox sort columns by clicking on header

STYoda 1 Reputation point
2021-08-24T22:24:20.907+00:00

Hi,

In Excel vba, I have a listbox in a Userform and would like to sort the column when a column header is clicked.
Is this possible?
So, if I click on column 6 header then it will arrange all the columns by column 6 alphabetically, and then if I clicked column 6 again then it would reverse the order.

126086-image.png

Thanks
ST

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Martin 1 Reputation point
    2022-01-18T22:58:08.26+00:00

    Yes.
    I presume that the listbox is being 'rowsourced' by a table/list in a sheet.
    If it was me - I would make the listbox commandheads property false then place command buttons above the headings, that when clicked go to the source sheet and sort the data as required, then re-source the listbox property.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.