sort specific column header

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Sort a specific column (with header) in descending order

Sort a specific column (with header) in descending order

resolvedResolved · High Priority · Version 365

Sanjhali has attended:
Excel VBA Introduction course

Sort a specific column (with header) in descending order

hi. Cna someone tell me the code to sort a speciifis column in descending order.

The column has a header name.

I tried to use the code by recording the macro but unable to understand that.

RE: Sort a specific column (with header) in descending order

Hi Sanjhali,

Thank you for the forum question.

Yes recording sorting can be difficult to understand. I hope my code below makes sense.

The line:
Worksheets("Sheet1").Sort.SortFields.Clear

makes sure that your data is back to default and prevent other sorting from interfere your sorting.

You will of course need to change my code to your data set. In my code the range("a1:e6") will be sorted by the header (column) in A1.


Sub MySortCode()

Worksheets("Sheet1").Sort.SortFields.Clear

Range("A1:E6").Sort Key1:=Range("A1"), Header:=xlYes

End Sub




Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Edited on Thu 17 Feb 2022, 10:24

RE: Sort a specific column (with header) in descending order

Thank you Jens. this is helpful

Wed 16 Feb 2022: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Removing custom dictionary entries

If you add something to the custom dictionary in Excel you cannot remove it. The way to get around this is to go into word and remove it there.

View all Excel hints and tips


Server loaded in 0.07 secs.