P
Paul Black
Hi,
The Macro Below Produces a Total ( nType ) and Grand Total ( nTypeTotal
) Related to Variable i.
I would However, like to Add at the Bottom ( Starting 2 Rows Down from
the Already Produced Grand Total in the Macro ) the Totals for the
Following Groups :-
Total for 103 to 122 = 351,106
Total for 123 to 142 = 160,900
Total for 143 to 162 = 30,227
Total for 163 to 182 = 1,512
Total for 183 to 203 = 1
Grand Total = 543,746
Here is the Macro :-
Option Explicit
Option Base 1
Sub Test()
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Dim F As Integer
Dim i As Integer
Dim nType(203) As Long
Dim nTypeTotal As Long
Dim rng As Range
Application.ScreenUpdating = False
Sheets("Results").Select
Range("B3").Select
For i = 103 To 203
nType(i) = 0
Next i
For A = 1 To 33 - 5
For B = A + 1 To 33 - 4
For C = B + 1 To 33 - 3
For D = C + 1 To 33 - 2
For E = D + 1 To 33 - 1
For F = E + 1 To 33
nType(A + B + C + D + E + F) = nType(A + B + C + D + E + F) + 1
Next F
Next E
Next D
Next C
Next B
Next A
nTypeTotal = ActiveCell.Row
For i = 103 To 203
ActiveCell.Offset(1, 0).Value = "Total for"
ActiveCell.Offset(1, 1).Value = i
ActiveCell.Offset(1, 2).Value = nType(i)
ActiveCell.Offset(1, 0).Select
Next i
ActiveCell.Offset(1, 0).Value = "Grand Total"
Set rng = ActiveCell.Offset(1, 2)
rng.FormulaR1C1 = "=Sum(R" & nTypeTotal & "C:R[-1]C)"
rng.Formula = rng.Value
Application.ScreenUpdating = True
End Sub
I have Tried Adapting "=Sum(R" & nTypeTotal & "C:R[-1]C)" which Works (
Thanks to Tom Ogilvy & Bob Phillips ) for the Grand Total in the Macro
Above But to NO Avail.
Is this Possible Using Code like the nTypeTotal to Output the Values
Instead of the Code Entering Formulas into the Worksheet Please.
Any Help will be Greatly Appreciated.
Thanks in Advance.
All the Best.
Paul
*** Sent via Developersdex http://www.developersdex.com ***
The Macro Below Produces a Total ( nType ) and Grand Total ( nTypeTotal
) Related to Variable i.
I would However, like to Add at the Bottom ( Starting 2 Rows Down from
the Already Produced Grand Total in the Macro ) the Totals for the
Following Groups :-
Total for 103 to 122 = 351,106
Total for 123 to 142 = 160,900
Total for 143 to 162 = 30,227
Total for 163 to 182 = 1,512
Total for 183 to 203 = 1
Grand Total = 543,746
Here is the Macro :-
Option Explicit
Option Base 1
Sub Test()
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Dim F As Integer
Dim i As Integer
Dim nType(203) As Long
Dim nTypeTotal As Long
Dim rng As Range
Application.ScreenUpdating = False
Sheets("Results").Select
Range("B3").Select
For i = 103 To 203
nType(i) = 0
Next i
For A = 1 To 33 - 5
For B = A + 1 To 33 - 4
For C = B + 1 To 33 - 3
For D = C + 1 To 33 - 2
For E = D + 1 To 33 - 1
For F = E + 1 To 33
nType(A + B + C + D + E + F) = nType(A + B + C + D + E + F) + 1
Next F
Next E
Next D
Next C
Next B
Next A
nTypeTotal = ActiveCell.Row
For i = 103 To 203
ActiveCell.Offset(1, 0).Value = "Total for"
ActiveCell.Offset(1, 1).Value = i
ActiveCell.Offset(1, 2).Value = nType(i)
ActiveCell.Offset(1, 0).Select
Next i
ActiveCell.Offset(1, 0).Value = "Grand Total"
Set rng = ActiveCell.Offset(1, 2)
rng.FormulaR1C1 = "=Sum(R" & nTypeTotal & "C:R[-1]C)"
rng.Formula = rng.Value
Application.ScreenUpdating = True
End Sub
I have Tried Adapting "=Sum(R" & nTypeTotal & "C:R[-1]C)" which Works (
Thanks to Tom Ogilvy & Bob Phillips ) for the Grand Total in the Macro
Above But to NO Avail.
Is this Possible Using Code like the nTypeTotal to Output the Values
Instead of the Code Entering Formulas into the Worksheet Please.
Any Help will be Greatly Appreciated.
Thanks in Advance.
All the Best.
Paul
*** Sent via Developersdex http://www.developersdex.com ***