Sort data in VBA in order of A-Z

randomguy

New Member
Joined
Dec 3, 2009
Messages
12
I would like to automaticly sort my data by the following:

Sort by column B
Sort based on values
In order of A-Z
(only on sheets "master" and "updates")

can i do this in VBA to make it automatic in my excel file?

I copy/paste data throughout the day into sheets in this workbook and would like it to always be sorted for me.

Also - the sheets master and updates are deleted throughout the day and re-created - so hopefully vba wont #ref all the ref's to the sheets as they will be back later?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You can create vba procedures to sort your data. Next time you do a regular short of your data turn on RecordMacro and then copy the generated code to your vba module. Need more information to give any specifics
 
Upvote 0
Woah that is cool!

Code:
    ActiveWorkbook.Worksheets("updates").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("updates").Sort.SortFields.Add Key:=Range("B2:B292" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("updates").Sort
        .SetRange Range("A1:P292")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
         End With

i would like that applied to two sheets in my book, where would i put it so its always sorted instead of assigning a button to it?
 
Upvote 0
You could use one of the Worksheet Event procedures to automatically short.

If youe use the Worksheet_Change event then everytime there is a chage of data on teh work sheet the sort procedure would run. YOu can limit it to run when only specified cells change dfata.

Need to know what triggers when the data is ready to be sorted.
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,322
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top