Alphabetize Rows with Macro

ThatGuyNamedDean

New Member
Joined
Apr 16, 2015
Messages
9
I am looking to alphabetize the rows of a spreadsheet based on the text in column A. The sorting also has to carry the information associated in the adjacent columns B though AK with the sorted information from column A. I would like to write this into a macro so a user can add data to the end of the previous work and press a button to have it sorted into the original. I'm not sure if this is possible so any help is much appreciated, thanks!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You can put the data in a table then use the autofilter function in VBA. The call looks like this:

Code:
    ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1" _
        ).Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1" _
        ).Sort.SortFields.Add Key:=Range("Table1[[#All],[Heat]]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
Upvote 0
Maybe start with this recorded macro, slightly modified.

Adjust sheet name.
Headers or No headers?? See the yes / no line for that.

Howard

Code:
Option Explicit

Sub SortOf()
    
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange ActiveSheet.UsedRange
        .Header = xlYes 'xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
End Sub
 
Upvote 0
Howard I have altered the code to fit my sheet and it runs with no errors but the actual alphabetizing does not happen.



Option Explicit




Sub SortOf()

With ActiveWorkbook.Worksheets("Database").Sort
.SetRange ActiveSheet.UsedRange
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,051
Messages
6,128,505
Members
449,455
Latest member
jesski

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