worked without problems
Main Topics
Browse All TopicsHi Everyone,
I Have a worksheet containing stock details. I want to sort data realtime by just clicking on the table headers. I know how to sort the data normally. But that way i have to run the sort for every header that i require and i waste a lot of time doing the sort manually
My worksheet contains the following headers...
Sr.No., Description, Package,active stock, order treshold, container, Stock update Date
Normally i sort my data on either of these headers - active stock, order treshold, container, Stock update Date
Can someone give me the macro to do this sort?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: Pedro80Posted on 2009-06-04 at 22:37:22ID: 24553569
If you put the attached code in the worksheet module of the worksheet containing the table you want to sort, you can just double click the header text to sort that column.
- Open VBA editor (ALT+F11)
- Open the project explorer if it's not already open (Ctrl+R)
- Locate the VBA project of your excel file and expand it (pressing the '+' icon)
- For each of the worksheets in your workbook you will have a module called Sheet1, Sheet2 etc. Double click the worksheet you want to implement easier sorting for
- Paste the below code into the module
- Modify the line that says [Const cstrHeadRngAdr As String = "A1:E1"] to where your header is located, for example your header can be located in the range "C3:X50" you would then change the line to read [Const cstrHeadRngAdr As String = "C3:X50"]
- Goto Excel again (ALT+F11)
- Find your worksheet at double click the header column you want to sort by..
Tell me how this works out for you, there are many ways of doing this sort of thing.Select allOpen in new window