+ Reply to Thread
Results 1 to 4 of 4

Sort Ascending for variable Report length

  1. #1
    Registered User
    Join Date
    09-24-2008
    Location
    UK
    Posts
    75

    Sort Ascending for variable Report length

    Hello,

    I'm trying to sort a report using case number in Ascending order, this report varies in length and data begins in cell B2 down the whole report. It needs to include the fields on either side ie. expand the selection.

    I've been using this with not much success : -

    Please Login or Register  to view this content.
    Thanks in advance for any help.
    Last edited by Hblbs; 02-11-2009 at 08:27 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Ascending for variable Report length

    er.. what / how is report_length defined ?

    presumably the below would work for you ?

    Please Login or Register  to view this content.
    the above assumes you have no data beneath the table being sorted.
    Last edited by DonkeyOte; 02-10-2009 at 01:05 PM.

  3. #3
    Registered User
    Join Date
    09-24-2008
    Location
    UK
    Posts
    75

    Re: Sort Ascending for variable Report length

    Thanks DonkeyOte, your code works fine.

    Below is what I should have been using, instead of report_length it should have been LastRow.

    Please Login or Register  to view this content.
    Thanks again for you contribution

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Ascending for variable Report length

    be warned that UsedRange can give misleading results given possibility of "dirty cells"... also if you want to persist with your approach I would advise you set LastRow to be .UsedRange.Row + .UsedRange.Rows.Count -1 rather than .UsedRange.Rows.Count ... the latter is potentially flawed should your data say at some point going forward change and commence from A2:Ax rather than A1... eg, assume data in A2:A10... Last Row returns 9 using rows.count method thus your resulting range becomes A2:A9 as opposed to the correct range of A2:A10, using the revised approach would generate A2:A10 correctly.

    EDIT: maybe better to use: ActiveSheet.Cells.SpecialCells(xlLastCell).Row
    (if you don't use the method outlined in my earlier example of course)
    Last edited by DonkeyOte; 02-11-2009 at 08:39 AM.

+ 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