# Auto sort Excel 2010



## oscy (Jan 19, 2012)

I'd like to autosort my workbook in excel 2010. I understand I must use a macro, but I'm very poor with programming skills. I realize it's a lot to ask to make a macro for me but if anyone could help me out I'd truly appreciate it.

What I want:

When I enter something in a cell in column R on worksheet "X" I want the following to happen:



Sort row 3 to 160 on sheet "Y" firstly by column B from highest value to lowest, secondly by column A alphabetically from A to Z (or actually Ö last letter of swedish alphabet).
Sort row 2 to 116 on sheet "Z" firstly by column B from highest value to lowest, secondly by column E from highest value to lowest, thirdly by column H from highest value to lowest and lastly by column A alphabetically from A to Ö.
Sort row 3 to 75 on sheet "Q" firstly by column C from highest value to lowest, secondly by column D from highest value to lowest, and lastly by column A alphabetically from A to Ö
Sort row 3 to 100 on sheet "W" firstly by column M from highest value to lowest and lastly by column A alphabetically from A to Ö
I take it there's quiet some coding needed to be done and for a novice like me I'm afraid I can't make this happen on my own 


Any help would be appreciated!


Best regards


----------



## RSpecianjr (Jan 20, 2010)

Hey oscy,

It is quite possible for you to do this yourself . 

VBA (Macros):

VBA is used in Microsoft office application and can be used between the applications or strictly the application you are using. A Macro is the easiest way to duplicate a series of steps you take over and over again. It also has the important ability to run after certain events, this ability is primarily what power-users use to Auto-sort.

Alright, so you know what to use, but don’t know how write code. No problem, Microsoft created a very user-friendly feature to record steps. Record a Macro. In Excel 2007 you can find this option in the lower left hand corner of the screen. It looks like a small window with a red dot in the upper left hand corner. If you click on that it will prompt you to name it. Name it whatever you would like (no spaces), then hit OK. It is now recording what you do within Excel. Go through your steps to sort your data, it is important to only do what you want to have repeated. When you are done, click the stop button. It replaced the Record Macro button.

Now, you have a macro that you can run whenever you want. Unfortunately, it isn’t automatic yet. There is one more step, adding the code we recorded to an event. Press ALT+F11. This will open up the VBA Editor. On the left hand side you will see VBAProject, under that you will see Microsoft Excel Objects and Modules. Let’s do a quick explanation of what those are. 

Microsoft Excel Objects will host your Worksheets and then the Workbook (ThisWorkbook) itself. All event macros will be housed inside either one of those worksheets or inside ThisWorkbook. 

Modules will host your code that is not dependant on an event. This is where we will find our recorded Macro (this is only going to be viewable after you have recorded a macro).

So, expand the Modules folder and double click on Module1. You should see code in there. Copy your code without the start (Sub Macro1()) or end (End Sub). This will be replaced by the event trigger. Now double click (under VBA Project) on the Worksheet that you want your sort to happen on.

This should open up a blank page. Above the blank page, you will see two drop-down menus. That read General and Declarations. Change the General Drop-down to Worksheet. Now, what read Declarations should read SelectionChange and you should have a Private Sub populate. If you paste your code in there, whenever you go from one cell to another, it will run your recorded code. In that second drop-down, it will give you a bunch of different event types. 

Hope this helps,

Robert D. Specian Jr.


----------

