DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2012

    Question Sorting a subtotaled spreadsheet programmatically

    I have created a spreadsheet using VB, populated it with a few thousand rows and subtotaled it using the Range().Subtotal method.

    So far so good!

    I now need to sort the rows by the subtotal value in the subtotal column. I know it's possible because I can do this 'manually' on the spreadsheet simply by clicking on the column head and hey-presto the groups are sorted, not the individual rows.

    I have tried the following code:

    Range(groupStartCell).Sort(Key1:=worksheet.Range("F2" & lastRow.ToString), Order1:=Interop.Excel.XlSortOrder.xlDescending, Orientation:=Interop.Excel.XlSortOrientation.xlSortRows, Header:=Interop.Excel.XlYesNoGuess.xlGuess, OrderCustom:=1, MatchCase:=False)

    and it does nothing!

  2. #2
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Try recording a macro, then do it manually, then stop the recording.

    The resulting code should be what you need.

  3. #3
    Join Date
    Dec 2012
    Thank you Hack, I'll try that.

Similar Threads

  1. VB Help for Spreadsheet!
    By anonymous in forum VB Classic
    Replies: 1
    Last Post: 04-23-2004, 11:49 PM
  2. Re: The eternal sorting debate. Where to do sorting
    By Willy Van den Driessche in forum VB Classic
    Replies: 11
    Last Post: 04-11-2002, 04:31 PM
  3. Spreadsheet
    By muirend in forum .NET
    Replies: 2
    Last Post: 09-28-2001, 11:04 AM
  4. VB and an Excel Spreadsheet
    By Dale Boyer in forum VB Classic
    Replies: 6
    Last Post: 01-29-2001, 12:57 PM
  5. VB and an Excel Spreadsheet
    By Dale Boyer in forum VB Classic
    Replies: 0
    Last Post: 01-26-2001, 02:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.