ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Use macro to sort column (https://www.excelbanter.com/excel-worksheet-functions/239773-use-macro-sort-column.html)

Paula

Use macro to sort column
 
I have 3 columns of info-B,C,D.
I want to sort the numbers in D in ascending order, but I need the info in B
and C to stay with the number in D.
I do not want to do it through "sort" because 5 worksheets has 77 rows, and
the sorting is in sections in those 77 rows. If you can show me the macro for
the first section, Rows 6-18, I can figure out the rest. Please do not leave
anything out of the macro, like the beginning and the end words, because I
cannot write them, I can only edit the ranges.
Thank You!
Paula

Luke M

Use macro to sort column
 
Macro to sorts B6:D18 by column D:

Sub SortByColumnD()
'Change first range as needed
'Do not change Key1
Range("B6:D18").Sort Key1:=Range("D1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Paula" wrote:

I have 3 columns of info-B,C,D.
I want to sort the numbers in D in ascending order, but I need the info in B
and C to stay with the number in D.
I do not want to do it through "sort" because 5 worksheets has 77 rows, and
the sorting is in sections in those 77 rows. If you can show me the macro for
the first section, Rows 6-18, I can figure out the rest. Please do not leave
anything out of the macro, like the beginning and the end words, because I
cannot write them, I can only edit the ranges.
Thank You!
Paula


Paula

Use macro to sort column
 
It worked perfect-thanks!!

"Luke M" wrote:

Macro to sorts B6:D18 by column D:

Sub SortByColumnD()
'Change first range as needed
'Do not change Key1
Range("B6:D18").Sort Key1:=Range("D1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Paula" wrote:

I have 3 columns of info-B,C,D.
I want to sort the numbers in D in ascending order, but I need the info in B
and C to stay with the number in D.
I do not want to do it through "sort" because 5 worksheets has 77 rows, and
the sorting is in sections in those 77 rows. If you can show me the macro for
the first section, Rows 6-18, I can figure out the rest. Please do not leave
anything out of the macro, like the beginning and the end words, because I
cannot write them, I can only edit the ranges.
Thank You!
Paula



All times are GMT +1. The time now is 10:34 PM.

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