Auto alphabetize individual columns

Adlcv99

New Member
Joined
Jul 24, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi. I am trying to figure out how to sort each column individually in alphabetical order if and when a new country name is added to that column. Picture attached of example data.
I have only been able to create a VBA to sort one column if a new country name is added but if will do nothing to the others just move them around based on the current sort. I cannout figure out how to get the other columns to sort as well individually when a new country name is added.
 
Greetings
Try this

VBA Code:
Sub test()
Sort Range("A1:E10") ' change A1:E10 as your request
'Call Sort(Range("A1:E10"))  ' change A1:E10 as your request
End Sub

Sub Sort(DataRng As Range)

'''''''''''''''' Note  without Header''''''''''''
Dim CLCnt As Long, RwCnt As Long
Dim SrtRng As Range

CLCnt = DataRng.Columns.Count 'Number of Columns
RwCnt = DataRng.Rows.Count    'Number of Rows

    For Cl = 1 To CLCnt 'to go through Range Columns On By on

    Set SrtRng = DataRng.Cells(1, Cl).Resize(RwCnt, 1) ' Sort Range column by column
        SrtRng.Sort Key1:=SrtRng.Cells(1, 1), Order1:=xlAscending, Header:=xlNo

    Next

End Sub
Thank you for your efforts but I couldn't get this one to work. There is another on in the thread that was able to work.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,215,426
Messages
6,124,828
Members
449,190
Latest member
rscraig11

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