Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sub Total collumns

Hi!


I have 3 collums of data

B C

1 45 200
1 50 333
2 60 500
2 10 500
2 80 90
3 90 30
3 800 20
4 80 10
5 250 5
6 300 3
6 60 80

I would like to run a loop which subtotalled my data twice based upon the
first
collumn (as below)

B C B Sub Totals C Sub Totals


1 45 200
1 50 333 95
533
2 60 500
2 10 500
2 80 90 150
1090
3 90 30
3 800 20 890
50
4 80 10 80
10
5 250 5 250
5
6 300 3
6 60 80 360
83

Thanks in advance

Darren

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200603/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Sub Total collumns

Sub ABC()
Dim lastrow As Long, ar As Range
Dim cell As Range, i As Long
Dim rng As Range
lastrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = lastrow To 1 Step -1
If Cells(i, 1) < Cells(i + 1, 1) Then
Rows(i + 1).Insert
End If
Next
Set rng = Columns(2).SpecialCells(xlConstants, xlNumbers)
For Each ar In rng.Areas
Set cell = ar(ar.Count).Offset(0, 2)
cell.Value = Application.Sum(ar)
Set cell = cell.Offset(0, 1)
cell.Value = Application.Sum(ar.Offset(0, 1))
Next
End Sub

This assumes your numbers are numeric constants - not produced by formulas
or numbers that are stored as text strings.

--
Regards,
Tom Ogilvy



"Darren via OfficeKB.com" wrote:

Hi!


I have 3 collums of data

B C

1 45 200
1 50 333
2 60 500
2 10 500
2 80 90
3 90 30
3 800 20
4 80 10
5 250 5
6 300 3
6 60 80

I would like to run a loop which subtotalled my data twice based upon the
first
collumn (as below)

B C B Sub Totals C Sub Totals


1 45 200
1 50 333 95
533
2 60 500
2 10 500
2 80 90 150
1090
3 90 30
3 800 20 890
50
4 80 10 80
10
5 250 5 250
5
6 300 3
6 60 80 360
83

Thanks in advance

Darren

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200603/1

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Sub Total collumns

Tom,

Thats just awesome

Thanks

Darren

Tom Ogilvy wrote:
Sub ABC()
Dim lastrow As Long, ar As Range
Dim cell As Range, i As Long
Dim rng As Range
lastrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = lastrow To 1 Step -1
If Cells(i, 1) < Cells(i + 1, 1) Then
Rows(i + 1).Insert
End If
Next
Set rng = Columns(2).SpecialCells(xlConstants, xlNumbers)
For Each ar In rng.Areas
Set cell = ar(ar.Count).Offset(0, 2)
cell.Value = Application.Sum(ar)
Set cell = cell.Offset(0, 1)
cell.Value = Application.Sum(ar.Offset(0, 1))
Next
End Sub

This assumes your numbers are numeric constants - not produced by formulas
or numbers that are stored as text strings.

Hi!

[quoted text clipped - 42 lines]

Darren


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200603/1
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
SUM IF sum of two collumns petran Excel Discussion (Misc queries) 2 November 18th 08 11:48 AM
Collumns Static Excel Discussion (Misc queries) 1 October 30th 07 07:32 AM
disappearing collumns Trintrin Excel Discussion (Misc queries) 1 April 4th 06 09:20 PM
Totalling Collumns Stormingerman Excel Worksheet Functions 1 December 19th 05 01:45 AM
Collumns and rows smintey Excel Discussion (Misc queries) 2 February 15th 05 05:10 PM


All times are GMT +1. The time now is 09:33 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"