Consulting

Results 1 to 4 of 4

Thread: Clean up Sort

  1. #1

    Clean up Sort

    When I recorded the sort function, it provided me with the exact range that I am using.
    I would like to clean it up so it does not matter how many rows my table is.

    [VBA]ActiveWorkbook.Worksheets("Master File").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Master File").Sort.SortFields.Add Key:=Range( _
    "C2:C2339"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Master File").Sort.SortFields.Add Key:=Range( _
    "B2:B2339"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Master File").Sort
    .SetRange Range("A1:O2339")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With[/VBA]

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    change to C:C and B:B and A:O

    see if that works.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  3. #3
    I can't believe it was that simple.

    Thanks

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Preseb,
    Please use the green VBA button to format posted code as shown.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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