VBA Sort a Column Named Disposition, but Disposition column will not be in defined column number it will vary

nsundarv

New Member
Joined
May 25, 2018
Messages
3
Dear Friends,
There are 43 columns
Sort Column Header Named Disposition.
But Disposition column will not be in defined column number (each time when we receive file columns will be shuffled)
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
It is a unclear whether you want to sort the Disposition column only or whether you want to sort all columns but based on the Disposition column.

See if one of these does what you want. Suggest you test with copies of your data.

Code:
Sub Sort_Disposition_Only()
  Dim Col As Long
  
  Col = Rows(1).Find(What:="Disposition", LookIn:=xlValues, LookAt:=xlWhole).Column
  Columns(Col).Sort Key1:=Cells(2, Col), Order1:=xlAscending, Header:=xlYes
End Sub



Sub Sort_All_Based_On_Disposition()
  Dim Col As Long
  
  Col = Rows(1).Find(What:="Disposition", LookIn:=xlValues, LookAt:=xlWhole).Column
  ActiveSheet.UsedRange.Sort Key1:=Cells(2, Col), Order1:=xlAscending, Header:=xlYes
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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