+ Reply to Thread
Results 1 to 8 of 8

Sort macro using CurrentRegion

  1. #1
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    Home/Office 2016
    Posts
    246

    Sort macro using CurrentRegion

    Attached sample
    I have a macro that runs across 3 worksheets sorting column F (high to low).
    The EXAMPLE macro is correct and runs fine. The REPORTGENERATOR runs the macro across all 3 worksheets.

    I tried to recreate the EXAMPLE macro on my own as SORTLASTCOL but keep "SECTION A" (the first tab name) in the macro instead of CURRENTREGION.

    What steps do I take to recreate the EXAMPLE macro?
    Attached Files Attached Files
    Last edited by x65140; 12-04-2013 at 06:54 AM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Sort macro using CurrentRegion

    This code runs on the active sheet. If sheet "Section" happens to be the active sheet (Where the cursor is when you run the code) and then sorts the data by column F. What needs to be done?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    Home/Office 2016
    Posts
    246

    Re: Sort macro using CurrentRegion

    This is an online class from work....not very clear. I'm attaching a WORKING.XLSM from class and my NEWONE.XLSM attempt.
    The SORTLASTCOL only points to the first tab, so when I run the REPORTGENERATOR and it gets to the second tab, it messes up the first tab results.
    Don't know how they created their SORTLASTCOL macro. (AND, it doesn't sort the second and third tab data)
    Attached Files Attached Files
    Last edited by x65140; 12-03-2013 at 02:02 PM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Sort macro using CurrentRegion

    SORTLASTCOL is for Worksheets("Section A") ONLY.
    The other codes you have do not have specific sheet names. They all work on the activesheet.

  5. #5
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    Home/Office 2016
    Posts
    246

    Re: Sort macro using CurrentRegion

    Understood. My main question is:
    How did they create their SORTLASTCOL to use CURRENTREGION? Every time I try, I get the worksheet name and that is what is messing me up.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Sort macro using CurrentRegion

    I personally do not like the sort code. In fact, I have recently only overcome my phobia on sorting .

    I have just adjusted the code to loop through all sheets except the "All section"
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Sort macro using CurrentRegion

    current region deals with range, not sheet names. Do you mean like this?

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    Home/Office 2016
    Posts
    246

    Re: Sort macro using CurrentRegion

    Yes, only without the 'Section A' in it. Like in their example....
    Did they KEY in the code, or did they CLICK buttons and have EXCEL create the code?
    I was looking for a way to CLICK to create the code...if that can't be done, I'll deal with what I have.....thanks.

    THEIR CODE:---------------------------
    Sub SortLastCol()
    '
    ' SortLastCol Macro
    '
    Range("A1").Select
    Selection.CurrentRegion.Select
    Selection.Sort Key1:=Range("F:F"), Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    '
    End Sub

+ 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. What is the best way to SUM a currentRegion?
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2013, 07:50 PM
  2. Using currentregion property
    By ingolf_ingolfsen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2011, 04:19 AM
  3. [SOLVED] Select first row of currentregion
    By vba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2006, 08:25 AM
  4. currentregion
    By flow23 in forum Excel General
    Replies: 13
    Last Post: 11-23-2005, 01:10 PM
  5. CurrentRegion less one Row
    By GregR in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-07-2005, 01:20 PM

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