Sorting a subtotaled spreadsheet programmatically


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Sorting a subtotaled spreadsheet programmatically

  1. #1
    Join Date
    Dec 2012
    Posts
    2

    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
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try recording a macro, then do it manually, then stop the recording.

    The resulting code should be what you need.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Dec 2012
    Posts
    2
    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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