Changing Column Order (Not Rows) with Sort Function

  • Thread starter Thread starter Trip Ives
  • Start date Start date
T

Trip Ives

Hello all,

I thought this would be easy - but I'm obviously mistaken. I want to
be able to order my columns in ascending or descending order (left to
right).

For examply A1 = Apple, B1 = Peach, C1 = Banana. I want to move
Banana (and all of its rows) between the Apple column and Peach
column. Could someone give me a chunk of sample code using sort
please. I've tried most everything but keep getting object errors as
soon as I throw in XLSortOrientation.

Any insight would be greatly appreciated!

Thanks!

Trip
 
Hi Trip.

Try:

Sub SortLrftToRight()
Dim rng As Range

Set rng = Range("A1:G10") '<==========AMEND!!

rng.Sort _
Key1:=rng(1), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlLeftToRight

End Sub
 
Just to add:
Easiest way to get the code and argument values is to turn on the macro
recorder while you do it manually.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top