Hello,
I'm trying to figure out how to sort columns independently of one another using VBA, and I have a good little piece of code that does this for me (see below). However, I've run into a couple of other things.
It seems like this should be so easy, but I've played enough to know I don't know where I need to head with this. Help please!
Here's the code I have...copied from ozgrid
Sub SortColumsIndividually()
Dim rCell As Range
For Each rCell In Range("A1:D1") 'Change range to suit
rCell.EntireColumn.Sort Key1:=rCell(2, 1), _
Order1:=xlAscending, Header:=xlYes
Next rCell
End Sub
I'm trying to figure out how to sort columns independently of one another using VBA, and I have a good little piece of code that does this for me (see below). However, I've run into a couple of other things.
- Some columns may need a custom sort order, not just ascending. What does something like this look like?
- I have 2 rows at the top, not just 1, that need to not be included in the sort. My code is working perfectly to exclude row 1, but grabs row 2 in the sort and I need it not to. Any ideas how to accomplish this?
It seems like this should be so easy, but I've played enough to know I don't know where I need to head with this. Help please!
Here's the code I have...copied from ozgrid
Sub SortColumsIndividually()
Dim rCell As Range
For Each rCell In Range("A1:D1") 'Change range to suit
rCell.EntireColumn.Sort Key1:=rCell(2, 1), _
Order1:=xlAscending, Header:=xlYes
Next rCell
End Sub