+ Reply to Thread
Results 1 to 6 of 6

Sorting a Range when the size of the range is not known in each of several worksheets

  1. #1
    Registered User
    Join Date
    04-25-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    9

    Post Sorting a Range when the size of the range is not known in each of several worksheets


    I have be attempting to sort a range of variable size (unknown until prior vb code is run). The sorting need to be completed on each of several sheets. The sheet name is passed to the module when the subroutine is called. It seems to sort the first sheet fine, then the range size get fixed for subsequent sheets and it only sorts the fixed portions. I want the range size to be adjusted to each sheets data. Also, within the columns there are sometime blanks but there is a total in the last column. This routine only sorts those columns before it runs into one that is blank leaving the totals column unsorted. Code is below - any help is much appreciated. I must be doing something obviously wrong - hope you can see it.
    I started from code someone else developed thinking I could modify for my purposes:

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-04-2013 at 03:14 PM. Reason: Added Code Tags

  2. #2
    Registered User
    Join Date
    07-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Sorting a Range when the size of the range is not known in each of several worksheets

    Looks to me like you're establishing your DataFirstCell and DataLastCell from the same worksheet each time.

    Here's a sample of your code

    Please Login or Register  to view this content.
    When my guess is it should be

    Please Login or Register  to view this content.
    Since it doesn't look like you're changing the active worksheet it keeps using the selection from the first sheet.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting a Range when the size of the range is not known in each of several worksheets

    Hi Cooper,

    Try this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    04-25-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sorting a Range when the size of the range is not known in each of several worksheets

    xladept - great - works fine. Thank you very much for the help. Poaabily you can help with another problem. My debugger highlights in yellow the following code (obviously indicating a probelm when trying to create subtotals from a sheet that has variable row length:
    Please Login or Register  to view this content.
    Anything obvious you can see?
    Thanks again...in advance
    Last edited by Leith Ross; 05-04-2013 at 03:15 PM. Reason: Added Code Tags

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting a Range when the size of the range is not known in each of several worksheets

    Hi Cooper,

    Maybe you need two fields here??
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-25-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sorting a Range when the size of the range is not known in each of several worksheets

    Appreciate the thought - still not certain what you mean, but I am not known as the sharpest knife in the drawer. Do you mean a total for all months and a total for invidiual months? When I sort by GroupBy 2 it is supposed to subtotal rows by month, and create a grand total at the end -SummaryBelowData. In fact nothing is happening - I run this following the sort routine that you helped me solve above that sorts the rows by month.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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