Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Run-time changes to subtotal parameter list

Always keep column 8 up to the lastcolumn -1?

If yes, how about something like:

Option Explicit
Sub testme()
Dim LastCol As Long
Dim vaper() As Long
Dim iCtr As Long
Dim usedCtr As Long
With Worksheets("sheet1")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With

If LastCol < 10 Then
MsgBox "error--in layout!"
Exit Sub
Else
ReDim vaper(1 To LastCol - 9)
vaper(1) = 8
For iCtr = 10 To LastCol - 1
vaper(iCtr - 8) = iCtr
Next iCtr
End If

End Sub

I used row 1 to get the lastused column. It should be pretty similar if you get
it some other way.

Graham Slade wrote:

I have a question about programmatically defining the
contents of an Array constant used for subtotal parameter.

My current code looks like this:
' Create an array for the columns to perform subtotals on
vaper1 = Array(8, 10, 11, 12, 13, 14, 15, 16, 17, 18)
vaper2 = Array(8, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22)
vaper3 = Array(8, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26)
If Int((lEndPer - lStartPer + 1) / 4) = 2 Then
vaPer = vaper1
Else
If Int((lEndPer - lStartPer + 1) / 4) = 3 Then
vaPer = vaper2
Else
vaPer = vaper3
End If
End If
With Worksheets("Sheet1").Range("B1")
.Subtotal groupBy:=1, Function:=xlSum, _
totalList:=vaPer, Replace:=True
End With

The purpose of the code is to insert subtotals on all the
columns up to the last column with data in it. The last
column is defined by the user during run-time so the
totalList parameter of the Subtotal method is not fixed.

My code is the best workaround I could manage to get me
over the first few months of running this, but I wonder if
anyone has a more general and elegant solution that would
work for any number of columns the user defined?

Any help appreciated.

Regards,

Graham


--

Dave Peterson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run-time changes to subtotal parameter list

Dave,

Sorted perfectly. As usual it's always obvious once you've seen the answer.

Many thanks,

Graham


"Dave Peterson" wrote in message
...
Always keep column 8 up to the lastcolumn -1?

If yes, how about something like:

Option Explicit
Sub testme()
Dim LastCol As Long
Dim vaper() As Long
Dim iCtr As Long
Dim usedCtr As Long
With Worksheets("sheet1")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With

If LastCol < 10 Then
MsgBox "error--in layout!"
Exit Sub
Else
ReDim vaper(1 To LastCol - 9)
vaper(1) = 8
For iCtr = 10 To LastCol - 1
vaper(iCtr - 8) = iCtr
Next iCtr
End If

End Sub

I used row 1 to get the lastused column. It should be pretty similar if

you get
it some other way.

Graham Slade wrote:

I have a question about programmatically defining the
contents of an Array constant used for subtotal parameter.

My current code looks like this:
' Create an array for the columns to perform subtotals on
vaper1 = Array(8, 10, 11, 12, 13, 14, 15, 16, 17, 18)
vaper2 = Array(8, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22)
vaper3 = Array(8, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26)
If Int((lEndPer - lStartPer + 1) / 4) = 2 Then
vaPer = vaper1
Else
If Int((lEndPer - lStartPer + 1) / 4) = 3 Then
vaPer = vaper2
Else
vaPer = vaper3
End If
End If
With Worksheets("Sheet1").Range("B1")
.Subtotal groupBy:=1, Function:=xlSum, _
totalList:=vaPer, Replace:=True
End With

The purpose of the code is to insert subtotals on all the
columns up to the last column with data in it. The last
column is defined by the user during run-time so the
totalList parameter of the Subtotal method is not fixed.

My code is the best workaround I could manage to get me
over the first few months of running this, but I wonder if
anyone has a more general and elegant solution that would
work for any number of columns the user defined?

Any help appreciated.

Regards,

Graham


--

Dave Peterson



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
List and subtotal selected items, then print separate item list TitanG Excel Worksheet Functions 0 September 8th 08 09:07 PM
Create a parameter list stockton12 Excel Discussion (Misc queries) 1 May 12th 08 04:45 PM
A list of data with time stamps, how subtotal at 10 min intervals John Excel Worksheet Functions 4 September 22nd 07 01:21 AM
How to choose if I use a parameter or not in a parameter query Arnaud Excel Discussion (Misc queries) 0 March 8th 07 01:19 PM
How do you dedupe a list in excel with parameter? mags Excel Worksheet Functions 1 April 18th 06 12:57 PM


All times are GMT +1. The time now is 11:19 AM.

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

About Us

"It's about Microsoft Excel"