Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Entering subtotals quickly in several columns

I am using Office 2003 on Windows XP.

I need VBA code to enter subtotals in several columns of numbers. The
structure of the sheet does not lend itself to using the built-in subtotal
command. The data is already divided into clusters with two row breaks
between each cluster. Each cluster needs to be subtotaled and each cluster
varies in length from 1 to several thousand rows. The sheet contains over
32,000 rows and the structure and length are dynamic (change daily). The data
is assembled by several different persons each adding their chunk(s) of data
from different sources into different sheets. I'm trying to help automate
putting the whole thing together.

1. I can't come up with a way to do this apart from looping thru the cells,
but I'm afraid this method will take too long to complete (I haven't
developed it yet, as I'm waiting until I get ideas from this post). Using
this method, is it faster to collect the target addresses first in an array
and then write formulas into those cells, or just For-Each-Cell straight thru?

2. I could have sworn that in previous versions of Excel, you could select a
column of values like I have described and you could click the AutoSum button
and it would enter totals automatically beneath each cluster for you, but my
Office 2003 version doesn't do this - or is there some other trick to that -
or am I just loosing it altogether?

Any ideas for a high speed solution?

Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Entering subtotals quickly in several columns

You have empty cells between each group?

You can pick out a column that "controls" the size of the group (I used column
D)?

And the entries in that column are constants, not formulas?

If yes to all:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myArea As Range

With Worksheets("Sheet1")
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("D2", .Cells(.Rows.Count, "D").End(xlUp)) _
.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "no constants!"
Exit Sub
End If

For Each myArea In myRng.Areas
With myArea
.Resize(1).Offset(.Cells.Count).Formula _
= "=sum(" & .Address(0, 0) & ")"
.Resize(1).Offset(.Cells.Count, 1).Formula _
= "=sum(" & .Offset(0, 1).Address(0, 0) & ")"
End With
Next myArea
End With

End Sub

This portion just adds a formula to the cell to the right:

.Resize(1).Offset(.Cells.Count, 1).Formula _
= "=sum(" & .Offset(0, 1).Address(0, 0) & ")"

You could add as many of these as you want--just make sure the .offset()'s are
what you want.

quartz wrote:

I am using Office 2003 on Windows XP.

I need VBA code to enter subtotals in several columns of numbers. The
structure of the sheet does not lend itself to using the built-in subtotal
command. The data is already divided into clusters with two row breaks
between each cluster. Each cluster needs to be subtotaled and each cluster
varies in length from 1 to several thousand rows. The sheet contains over
32,000 rows and the structure and length are dynamic (change daily). The data
is assembled by several different persons each adding their chunk(s) of data
from different sources into different sheets. I'm trying to help automate
putting the whole thing together.

1. I can't come up with a way to do this apart from looping thru the cells,
but I'm afraid this method will take too long to complete (I haven't
developed it yet, as I'm waiting until I get ideas from this post). Using
this method, is it faster to collect the target addresses first in an array
and then write formulas into those cells, or just For-Each-Cell straight thru?

2. I could have sworn that in previous versions of Excel, you could select a
column of values like I have described and you could click the AutoSum button
and it would enter totals automatically beneath each cluster for you, but my
Office 2003 version doesn't do this - or is there some other trick to that -
or am I just loosing it altogether?

Any ideas for a high speed solution?

Thanks much in advance.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Entering subtotals quickly in several columns

In the words of Gomer Pyle, shazzam!

Thanks a lot Dave! I never thought of using special cells like that!

"Dave Peterson" wrote:

You have empty cells between each group?

You can pick out a column that "controls" the size of the group (I used column
D)?

And the entries in that column are constants, not formulas?

If yes to all:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myArea As Range

With Worksheets("Sheet1")
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("D2", .Cells(.Rows.Count, "D").End(xlUp)) _
.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "no constants!"
Exit Sub
End If

For Each myArea In myRng.Areas
With myArea
.Resize(1).Offset(.Cells.Count).Formula _
= "=sum(" & .Address(0, 0) & ")"
.Resize(1).Offset(.Cells.Count, 1).Formula _
= "=sum(" & .Offset(0, 1).Address(0, 0) & ")"
End With
Next myArea
End With

End Sub

This portion just adds a formula to the cell to the right:

.Resize(1).Offset(.Cells.Count, 1).Formula _
= "=sum(" & .Offset(0, 1).Address(0, 0) & ")"

You could add as many of these as you want--just make sure the .offset()'s are
what you want.

quartz wrote:

I am using Office 2003 on Windows XP.

I need VBA code to enter subtotals in several columns of numbers. The
structure of the sheet does not lend itself to using the built-in subtotal
command. The data is already divided into clusters with two row breaks
between each cluster. Each cluster needs to be subtotaled and each cluster
varies in length from 1 to several thousand rows. The sheet contains over
32,000 rows and the structure and length are dynamic (change daily). The data
is assembled by several different persons each adding their chunk(s) of data
from different sources into different sheets. I'm trying to help automate
putting the whole thing together.

1. I can't come up with a way to do this apart from looping thru the cells,
but I'm afraid this method will take too long to complete (I haven't
developed it yet, as I'm waiting until I get ideas from this post). Using
this method, is it faster to collect the target addresses first in an array
and then write formulas into those cells, or just For-Each-Cell straight thru?

2. I could have sworn that in previous versions of Excel, you could select a
column of values like I have described and you could click the AutoSum button
and it would enter totals automatically beneath each cluster for you, but my
Office 2003 version doesn't do this - or is there some other trick to that -
or am I just loosing it altogether?

Any ideas for a high speed solution?

Thanks much in advance.


--

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
Adding small units of time and entering them quickly ckdkvk Excel Discussion (Misc queries) 1 January 4th 06 08:15 AM
Subtotals multiple columns john liem Excel Worksheet Functions 0 July 6th 05 01:08 PM
Subtotals multiple columns john liem Excel Worksheet Functions 1 July 5th 05 06:06 PM
Entering date QUICKLY DOMINIC JOSLIN New Users to Excel 2 December 10th 04 09:47 AM
Entering dates QUICKLY DOMINIC JOSLIN Excel Discussion (Misc queries) 4 December 10th 04 09:46 AM


All times are GMT +1. The time now is 11:21 PM.

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"