Sum the numbers Generated by Macro within macro.

3PlankWalker

Board Regular
Joined
Sep 18, 2014
Messages
76
I have this Macro to print the numbers 1 to 10 in three rows As shown in the image below

6oi2mmqt7

View image: Sum

Code:
Sub SumLoop()Dim a(1 To 3), Count, d, i As Integer
a(1) = 1
a(2) = 2
a(3) = 4


For i = 1 To UBound(a)
    d = 0
    Count = 0
    Do While d < 10
    Count = Count + 1
            d = d + 1
            Cells(Count, 1 + Count2).Value = d
    Loop
    Count2 = Count2 + 1
Next i
End Sub

How can i add the D1=A1+B1+C1, D2=A2+B2+C2 ...
within the macro
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try this:-
Code:
Sub SumLoop()
Dim a(1 To 3), Count, d, i As Integer
Dim count2
a(1) = 1
a(2) = 2
a(3) = 4




For i = 1 To UBound(a)
    d = 0
    Count = 0
    Do While d < 10
    Count = Count + 1
            d = d + 1
            Cells(Count, 1 + count2).Value = d
[B]            Cells(Count, 4) = Application.Sum(Cells(Count, 1).Resize(, 3).Value)[/B]
    Loop
    count2 = count2 + 1
Next i
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,487
Messages
5,831,972
Members
430,099
Latest member
rdhoy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top