ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How can I sort contents of one column based on the contents ofanother column? (https://www.excelbanter.com/excel-programming/405842-how-can-i-sort-contents-one-column-based-contents-ofanother-column.html)

[email protected]

How can I sort contents of one column based on the contents ofanother column?
 
I have some data in column "A" and random numeric values in column
"B".
I want to sort column "A" based on the ascending order of column "B".
I was able to do it manually by selecting both the columns and
sorting. But i dont know how to do it in a macro...

FSt1

How can I sort contents of one column based on the contents of ano
 
hi
Dim r As Range
Set r = Range("A1", Range("A1").End(xlDown).Offset(0, 1))

r.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

when ever you hit a syntax snag, do what i do. turn on the recorder and
perform the desired actions manually. most of the time, the recorder will
show you the basic syntax and give you a basic idea of how to code it.
sometimes editing is reguired but you do get the basic idea. very helpful for
people just starting out.

Regards
FSt1

" wrote:

I have some data in column "A" and random numeric values in column
"B".
I want to sort column "A" based on the ascending order of column "B".
I was able to do it manually by selecting both the columns and
sorting. But i dont know how to do it in a macro...



All times are GMT +1. The time now is 03:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com