sorting column and expanding selection

tanyaleblanc

Board Regular
Joined
Mar 16, 2019
Messages
145
just looking to sort column D in ascending order, but I need all the columns to sort as well. When I use this code, its just sorting column d and the rest of the columns are mixed up and my data is now incorrect.

I do have a header in row 2 that I don't want included in the sort. I just want to sort everything from D3 down and expand selection so everything gets sorted correctly

Range("D3:d500").Sort Key1:=Range("d3"), Order1:=xlAscending, Header:=xlNo
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
the file has columns from A to T, row 2 is the headers, I want to sort by column D (acct#), but all the other columns need to expand to sort those too

for example. I want to sort the below by column D, but all the other data in the other columns need to be sorted with it so that each row has the correct data within it.

Value Combo Value Acct#Cost CentreAcct #NametypePCGross AmtCommentSL
10494293104942911049429 JOAN M JOHNSTON1191$470.20Payout3
10494293104942911049429 JOAN M JOHNSTON1214($24.04)Payout3
10876352108763511087635 WILMA SMITH1191$330.00Payout2

<colgroup><col span="2"><col><col><col><col span="2"><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
If it is just A to T then it is just

Code:
Range("A3:T500").Sort Key1:=Range("d3"), Order1:=xlAscending, Header:=xlNo
or
Code:
Range("A2:T500").Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes
Or if an unknown number of columns then
Code:
Range(Cells(2, "A"), Cells(500, Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column)).Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes
 
Upvote 0
If it is just A to T then it is just

Code:
Range("A3:T500").Sort Key1:=Range("d3"), Order1:=xlAscending, Header:=xlNo
or
Code:
Range("A2:T500").Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes
Or if an unknown number of columns then
Code:
Range(Cells(2, "A"), Cells(500, Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column)).Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes

Thank so much for letting me yoink your code! :)
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

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