Visual basic sort on active sheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • justjen
    New Member
    • Jun 2013
    • 1

    Visual basic sort on active sheet

    I want to run a sort on the active sheet regardless of what sheet is active. How do I rewrite the following without a sheet name so that it will just run on the sheet that is active when the macro is called to run. I want to get rid of "Master Daily calc" and have the macro just run on the sheet that is active at the time.

    Code:
    Range("B5:E37").Select
        ActiveWorkbook.Worksheets("Master Daily calc").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Master Daily calc").Sort.SortFields.Add Key:=Range _
            ("B5:B37"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Master Daily calc").Sort
            .SetRange Range("B4:E37")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    Last edited by Rabbit; Jun 21 '13, 04:12 AM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    Your thread has been moved to the Access forum.

    Use ActiveSheet.

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      Replace "Master Daily calc" with this: ActiveSheet.Nam e

      Comment

      Working...