+ Reply to Thread
Results 1 to 7 of 7

Sort Select Range: Either Find Column Header or Last Column:Last Row

  1. #1
    Registered User
    Join Date
    06-24-2014
    Location
    SC
    MS-Off Ver
    2007 - 2013
    Posts
    12

    Sort Select Range: Either Find Column Header or Last Column:Last Row

    Please Login or Register  to view this content.
    My code was hard coded to sort on Column F, and I just guessed by going to row 50 that it would go past my actual data. Today it failed and I realized it failed because my raw data had an extra column. The column I need to sort on is "Grand Total". Because of the extra column, it was now Column G instead of F. So apparently it may not be consistently in the same place. So can I include a FIND in the range selection? Also include something that looks for the last row of data?

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,258

    Re: Sort Select Range: Either Find Column Header or Last Column:Last Row

    Try it like this:
    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-24-2014
    Location
    SC
    MS-Off Ver
    2007 - 2013
    Posts
    12

    Re: Sort Select Range: Either Find Column Header or Last Column:Last Row

    That's close. The Grand Total column header is merged between H1:H2. Attached is a sample set.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,258

    Re: Sort Select Range: Either Find Column Header or Last Column:Last Row

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-24-2014
    Location
    SC
    MS-Off Ver
    2007 - 2013
    Posts
    12

    Re: Sort Select Range: Either Find Column Header or Last Column:Last Row

    So I've spent the better part of the day trying to learn and understand vba range select statements. I've attached a new sample report. This has 2 tabs. What my normal raw data looks like and what it looks like after I ran my macro with a hard coded Column F. Below is my entire CODE. Bernie's last update does sort of sort on the "Grand Total" column but doesn't move up the "Grand Total" row. This code was working well for me until a new column was inserted and it thew everything off. So I'm trying to adjust the code to be dynamic based on possible changes in the raw data.

    Please Login or Register  to view this content.
    Here is some code I found that I thought might help me, but I couldn't get it to work.
    Please Login or Register  to view this content.
    I'm also trying to learn from this, particularly the ability to select various ranges. Seems like a skill that will always be useful using vb macros, so I won't have to ask for everything and eventually be able to help others
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,258

    Re: Sort Select Range: Either Find Column Header or Last Column:Last Row

    I did not 'move up' the Grand Total row because the summary should remain at the bottom. To get it to move up, use this, which just removes the -1 from the .SetRange line:

    Please Login or Register  to view this content.
    As a side note - merged cells and multiple rows of headers are things you should avoid in your workbook design.

  7. #7
    Registered User
    Join Date
    06-24-2014
    Location
    SC
    MS-Off Ver
    2007 - 2013
    Posts
    12

    Re: Sort Select Range: Either Find Column Header or Last Column:Last Row

    I'll give that a try. The data is generated from the salesforce application, so I can't alter the design. At least not that I'm aware of at this time.

    Thanks Bernie

+ 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. Find Column Header that includes String, then use that Address as Sort Key1
    By TimBZKK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-07-2013, 05:17 PM
  2. Replies: 1
    Last Post: 10-05-2013, 03:35 PM
  3. Range Select Based on Column Header
    By Nospmas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-24-2013, 11:27 AM
  4. VBA to select data range, and sort by a column
    By Pete123abc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2011, 03:28 PM
  5. Find last numerical value in row range and return the column header
    By Fidd$ in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-04-2011, 10:15 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