+ Reply to Thread
Results 1 to 8 of 8

Sorting sheets by calling sub procedures.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Sorting sheets by calling sub procedures.

    Good day,
    I am just looking to enhance this procedure when sorting. My setting is at the “Page Break Preview”. I feel like the view is much better, I guess to each their own.
    I have sorting procedure stored in my module 3, I have around 6 sorting that will sort different sheets. In some of my codes, I call sometime 3 at a time as my information constantly updates.
    I was looking at my sheet after the procedure was running and it was not doing as the code is written. I am just looking to see if this could be improved or and modified to not have the print selection “Snapped on” when I call these procedures.
    Sort from Sheet1:
    Sub Sort1()
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        With ActiveWorkbook.Worksheets("Pre-Solicitation").Sort
            .SetRange Range("A5:M20")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A5").Select
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub
    The reason I am adding the Range selection at the end is that I havent found how to deselect the full screen. When I call the Sub Proceedure on 2 different Sorts it will generate the first sheet while doing the full proceedure but then if I go to my sheet2 I will see that it did not run the range selection.

    Sheet 2 sub:
    Sub Sort2()
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        With ActiveWorkbook.Worksheets("GETS").Sort
            .SetRange Range("A5:F20")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A5").Select
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub
    Is there a method for the Sheet to do like a unselect all...
    Last edited by Excelnoub; 05-09-2014 at 07:41 AM.

  2. #2
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Sorting sheets by calling sub procedures.

    I also have this in a userfrom:

    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    '..........Other proceedures
    
         Call Sort1
         Call Sort2
         Call Sort5
         Unload Me
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
        
    End Sub

  3. #3
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Sorting sheets by calling sub procedures.

    This is what I have to insert in my Userform everytime but was wondering if there would be an easier method

    Sheets("Pre-Solicitation").Select
    Range("A5").Select
    Sheets("GETS").Select
    Range("A5").Select
    Sheets("Pre-Solicitation").Select
    So that my Code would look like this at the end:

    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    '..........Other proceedures

    Call Sort1
    Call Sort2
    Call Sort5
    Unload Me

    Sheets("Pre-Solicitation").Select
    Range("A5").Select
    Sheets("GETS").Select
    Range("A5").Select
    Sheets("Pre-Solicitation").Select

    Application.ScreenUpdating = True
    Application.EnableEvents = True

    End Sub

    But I don't get it cause I am doing the same thing in my Sub Sort...

  4. #4
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Sorting sheets by calling sub procedures.

    I guess for a better understanding of what it is doing:

    You will see that when you Click on Sort 1 it will do exacly what it is supposed to do but when you click and Sort 1 and 2 or Sort all it will Select all information on sheet from Sheet2 and 3.

    I need to remove the selection.

    Sort.xlsm

  5. #5
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Sorting sheets by calling sub procedures.

    Found a shorter code for my Subs but when I call them Only the first sub is generated:


    Module1
    Sub Sort1()
        With Sheets(1)
        Range("A5:M20").Sort Key1:=Range("A5")
        End With
    End Sub
    
    Sub Sort2()
        With Sheets(2)
        Range("A5:F20").Sort Key1:=Range("A5")
        End With
    End Sub
    
    Sub Sort3()
        With Sheets(3)
        Range("A5:E20").Sort Key1:=Range("A5")
        End With
    End Sub
    Sheet1:

    Private Sub CommandButton1_Click()
        Call Sort1
    End Sub
    
    Private Sub CommandButton2_Click()
        Call Sort1
        Call Sort2
    End Sub
    
    Private Sub CommandButton3_Click()
        Call Sort1
        Call Sort2
        Call Sort3
    End Sub
    Last edited by Excelnoub; 05-09-2014 at 12:04 PM.

  6. #6
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Sorting sheets by calling sub procedures.

    GOT IT

    Module:
    Sub Sort1()
        With ActiveWorkbook.Worksheets("Pre-Solicitation").Select
        Range("A5:M20").Sort Key1:=Range("A5")
        Range("A5").Select
        End With
    End Sub
    
    Sub Sort2()
        With ActiveWorkbook.Worksheets("GETS").Select
        Range("A5:F20").Sort Key1:=Range("A5")
        Range("A5").Select
        End With
    End Sub
    
    Sub Sort3()
        With ActiveWorkbook.Worksheets("Evaluation").Select
        Range("A5:E20").Sort Key1:=Range("A5")
        Range("A5").Select
        End With
    End Sub

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Sorting sheets by calling sub procedures.

    Your Withs aren't really doing anything.

    Try sprinkling some dot qualifiers, '.', over the code.
    Sub Sort1()
        With ActiveWorkbook.Worksheets("Pre-Solicitation")
            .Range("A5:M20").Sort Key1:=.Range("A5")
        End With
    End Sub
    
    Sub Sort2()
        With ActiveWorkbook.Worksheets("GETS")
            .Range("A5:F20").Sort Key1:=.Range("A5")
        End With
    End Sub
    
    Sub Sort3()
        With ActiveWorkbook.Worksheets("Evaluation")
            .Range("A5:E20").Sort Key1:=.Range("A5")
        End With
    End Sub
    If posting code please use code tags, see here.

  8. #8
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Sorting sheets by calling sub procedures.

    Once again... lol

    You have better my code.

    Thank you Norie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help calling functions to sub procedures
    By xXNetRavenXx in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-27-2010, 01:47 PM
  2. [SOLVED] Calling procedures from within VBA
    By Alex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2006, 08:50 AM
  3. [SOLVED] Event procedures: who is calling?
    By Momo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2006, 03:20 AM
  4. calling procedures from worksheet buttons
    By Anthony in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2005, 07:05 AM
  5. calling procedures (newbie here )
    By Piyush in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-01-2005, 11:21 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1