# Simple Excel Addition Calculations using VB

#### lashutm

##### New Member
I have a Macro in Access that throws a 2 and a 4 into Excel, such as: | 2 | 4 | (which I then create a chart from).

I want my array to then add a column with calculated data from the numbers I threw in from Access, such as: | 2 | 4 | 2 + 4 |, to look like | 2 | 4 | 6 |.

Using VB code, how would I create the new column (so as to throw it into the chart)? I have tried the macro recorder to no avail.

### Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Need clarification.... when you say it is thrown into Excel Where, does the code then create the chart or do you do it. Basically, you could create the new column like so though, say you have 2 in A1 and 4 in A2:

Code:
``Range("A3").Value = Range("A1").Value + Range("A2").Value``

I am not real sure how far you want to go with this though.

Not quite working.

Here is the code that throws the data into an excel array:

Dim StatsArray(1 To 5, 1 To 3) As Integer
Dim db As Database
Dim QueryByYear As QueryDef
Dim rs As Recordset

'---- 1st set of data ----------------
Set db = CurrentDb()
Set QueryByYear = db.QueryDefs("Query 1")
Set rs = QueryByYear.OpenRecordset()
With rs
StatsArray(1, 1) = rs!A
StatsArray(2, 1) = rs!B
StatsArray(3, 1) = rs!C
StatsArray(4, 1) = rs!D
StatsArray(5, 1) = rs!E
End With
'---- end of 1st set of data

'---- 2nd set of data ----------------
Set db = CurrentDb()
Set QueryByYear = db.QueryDefs("Query 2")
Set rs = QueryByYear.OpenRecordset()
With rs
StatsArray(1, 2) = rs!A
StatsArray(2, 2) = rs!B
StatsArray(3, 2) = rs!C
StatsArray(4, 2) = rs!D
StatsArray(5, 2) = rs!E
End With
'---- end of 2nd set of data

I now what to be able to take (1,1) + (1,2) and throw this calculation in(1,3). (2,3) = (2,1) + (2,2), etc. . .

Any ideas!

bump

Replies
7
Views
205
Replies
6
Views
374
Replies
1
Views
190
Replies
1
Views
331
Replies
1
Views
118

1,220,951
Messages
6,157,030
Members
451,392
Latest member
malcv

### 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.

### Which adblocker are you using?

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

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