Results 1 to 2 of 2

Thread: VBA Sort a Column Named Disposition, but Disposition column will not be in defined column number it will vary
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    May 2018
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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)

  2. #2
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    41,393
    Post Thanks / Like
    Mentioned
    100 Post(s)
    Tagged
    21 Thread(s)

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

    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
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •