98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Automatically sort data using VBA
Automatically sort data using VBA
Resolved · High Priority · Version 2013
Laura has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Automatically sort data using VBA
Hi,
I've got a table in excel that covers the range B14:D160. The data in it is generated mostly from VLookups, so change when the source table is changed or added to. I want it to be automatically sorted based on the contents of column 3, in ascending order, without the user having to re-sort it manually or by clicking on a button. It would be perfect if it could all happen 'behind the scenes' instead.
I've been able to get as far as getting a macro that will do this linked to a button but not one that will operate without any user input.
Any guidance you can give me would be great! (And if possible lots of explanatory comments - I'm still quite new to this!)
Thanks
RE: Automatically sort data using VBA
Hello Laura,
Thank you for your question. Have you got code which runs the Vlookup part of the data? If so, why not copy and paste the sorting code into that macro? If not, it would be a good idea to record a macro which runs the Vlookup function on the data and then paste the sorting code into that. Excel can record and run formulas and functions.
Just remember not to paste the Sub / End Sub lines of the sorting code. Also check the code so that the correct column is sorted. I assume this is column D.
I hope this helps a bit. Please post again if not.
Kind regards
Marius Barnard
Excel Trainer
RE: Automatically sort data using VBA
Hi Marius,
Thanks for the reply. At the moment all the Vlookups are achieved through formulas in the cells in the table. I could program this but I'm not sure this would help. This would give me a macro which would pull in the data and sort it, but I think my main problem is that I don't know how to get the macro to run only when a change has occurred in the source table. I can manage to get it to run by linking it to a button that then gets clicked, but the aim is to have it occur without the user having to do anything.
Hope that made sense....
Many Thanks
Laura
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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Convert Text into NumberSome times numbers maybe imported in as text or you maybe concatenating numbers that form a text string that now are treated, because you had to extract them by Text functions |