Consulting

Results 1 to 11 of 11

Thread: VBA Macro Sort Range

  1. #1

    VBA Macro Sort Range

    Hi All,
    I have to think this is a layup for experts. I have a Range that I want to sort based on the active column.

    Range("A2:AZ251").Sort Key1:=Cells(1,ActiveCell.Column) _
    Order1:=xlAscending, _
    Header:=xlYes

    Not working

    Thanks for your help,
    Will

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    try this:
    Range("A2:AZ251").Sort Key1:=Cells(1, ActiveCell.Column), _
    Order1:=xlAscending, _
    Header:=xlYes

  3. #3
    Still not the case

    i do love that the single comma was the change :-D

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,197
    Location
    Is it the top row that is not sorting, try extending the range to include the header:
        Range("A1:AZ251").Sort Key1:=Cells(1, ActiveCell.Column), _ 
        Order1:=xlAscending, _
        Header:=xlYes
    Or if your header is in row 2 then maybe:
        Range("A2:AZ251").Sort Key1:=Cells(2, ActiveCell.Column), _
        Order1:=xlAscending, _
        Header:=xlYes
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    Header is in row 1. Even with the change you proposed, still nothing happens. Worksheet doesnt move in anyway.

    Thanks for your help nonetheless. Really hope to crack this as it will make a HUGE difference.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Can you supply a sample workbook?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    I don't understand..... My sorts without problem

  8. #8
    Quote Originally Posted by Aussiebear View Post
    Can you supply a sample workbook?
    Attached Files Attached Files

  9. #9
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,197
    Location
    See attached, select any cell with green background and white writing and click the button on the worksheet.
    Attached Files Attached Files
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Man that worksheet is hard on the eyes.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  11. #11
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Windows(1).Zoom = 120
      With Range("A1:AZ250")
          .Font.Size = 9
          If Not Intersect(.Offset, ActiveCell) Is Nothing Then .Sort .Cells(1, ActiveCell.Column), , , , , , , 1
      End With
    End Sub

Posting Permissions

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