excel VBA: Alphabetize a multicolumn dynamic named range

jedwardo

Board Regular
Joined
Aug 21, 2012
Messages
122
Hello Everyone,

I have a multicolumn dynamic range linked to a multicolumn combobox on a userform. Am trying to find a way to alphabetize the range top to bottom, left to right as so:

Col1 Col2 Col3

a h o
b i p
c j
d k
e l
f m
g n

Can't find a method that doesn't sort each column separately. My second thought was create one dynamic named range in a single column that will alphabetize and then be the source for the second multicolumn range but couldn't find a way to use a dynamic range as a second dynamic ranges source either.

Any thoughts?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Your idea is valid. Your main list will be in a "helper column". Put all items in one column and sort it. Then, in the columns where your data currently is become links to the helper column. No need to change or dynamic range or anything else, just change the cells within that range to be links to the helper column instead of the data directly.
 
Upvote 0
Assuming there are no blank cells within the data in each column, the following macro allows for each column to end at a different row and it will fill those columns down to the last used row within that column with the sorted data downward first before moving to the next column (as your example shows you want it)...
Code:
[table="width: 500"]
[tr]
	[td]Sub AlphabetizeMultleColumnsByColumnsFirst()
  Dim C As Long, X As Long, LR As Long, V As Variant, Data As Variant
  Data = Range("A1").CurrentRegion.Value
  With CreateObject("System.Collections.ArrayList")
    For Each V In Data
      If V <> "" Then .Add V
    Next
    .Sort
    Data = Application.Transpose(.ToArray)
    X = 1
    For C = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
      LR = Cells(Rows.Count, C).End(xlUp).Row
      Cells(1, C).Resize(LR) = Application.Index(Data, Evaluate("ROW(" & X & ":" & X + LR - 1 & ")"))
      X = X + LR
    Next
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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