Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trying to Sort and Subtotal with Vbscript in Excel

I'm using VBScript and my output creates a worksheet with 7 columns
and I would like to sort and subtotal column 7 or G. I'm using the
below code and get an error at the subtotal row. I've search all over
Google and Microsoft, tried several different variations, no luck. I
have also put a message in the vbscript group.

objExcel.worksheets(Var1).Activate
' Set the sort key to be G
objExcel.Columns("G:G").Select
Set Key1 = objExcel.Range("G2")
objExcel.Columns("A:G").Sort Key1,1

' Subtotal where column G changes and count rows
objExcel.Columns("A:G").Subtotal 7, xlCount, Array(7), True, False,
True

I get the error Subscript out of range: '[number: 7]. code 800A0009

I can post more of the code, if needed.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trying to Sort and Subtotal with Vbscript in Excel

The following worked fine for me:

Sub aaSubtotal()
Set objExcel = Application
Var1 = "Sheet3"
objExcel.Worksheets(Var1).Activate
' Set the sort key to be G
objExcel.Columns("G:G").Select
Set Key1 = objExcel.Range("G2")
objExcel.Columns("A:G").Sort Key1, 1, Header:=True
' Subtotal where column G changes and count rows
objExcel.Columns("A:G").Subtotal 7, xlCount, Array(7), True, False, True

End Sub

the only thing I added was an argument to the sort to specify that the data
had headers (it should).

--
Regards,
Tom Ogilvy

"Jeremy Smith" wrote in message
om...
I'm using VBScript and my output creates a worksheet with 7 columns
and I would like to sort and subtotal column 7 or G. I'm using the
below code and get an error at the subtotal row. I've search all over
Google and Microsoft, tried several different variations, no luck. I
have also put a message in the vbscript group.

objExcel.worksheets(Var1).Activate
' Set the sort key to be G
objExcel.Columns("G:G").Select
Set Key1 = objExcel.Range("G2")
objExcel.Columns("A:G").Sort Key1,1

' Subtotal where column G changes and count rows
objExcel.Columns("A:G").Subtotal 7, xlCount, Array(7), True, False,
True

I get the error Subscript out of range: '[number: 7]. code 800A0009

I can post more of the code, if needed.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort macro, subtotal and add lines after subtotal David Excel Discussion (Misc queries) 1 August 29th 09 10:56 AM
How do I Subtotal, then Sort by Subtotal Amounts? dnamertz Excel Discussion (Misc queries) 3 October 29th 06 12:17 AM
Excel subtotal group sort rick@bcbsne Excel Worksheet Functions 4 October 13th 05 12:31 AM
Using VBScript to create Excel SS and sort by column. KevinW Excel Programming 0 December 29th 03 09:01 PM
How to do selection.subtotal in VBScript/ASP ? Wes[_5_] Excel Programming 3 December 9th 03 09:43 PM


All times are GMT +1. The time now is 08:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"