Simple Excel Addition Calculations using VB

lashutm

New Member
Joined
Aug 7, 2007
Messages
10
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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.
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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
Back
Top