VBA Macro sum matching cells in two workbooks

Dendennydenden

New Member
Joined
Mar 5, 2018
Messages
7
Hi. First time posting so please be gentle.

I am new to VBA and trying to get a grip of it, and having searched everywhere i cannot find anything that will solve this problem.
I have two identical workbooks containing numerical data:
Master01
Data01

I need a macro that takes the data in each cell (in a set range) in Data01 and adds it to the corresponding cell in Master01.
eg.
Master01, Sheet1, C10 = 7
Data01, Sheet1, C10 = 4
- run macro -
Master01, Sheet1, C10 = 11.

... and this is repeated for each cell C10:S63

Can this be done?
All help really appreciated.

den
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
It would be pretty simple to write but also dangerous. If you ran this over and over you keep adding your data cells value to the master over and over. Why not just make a 3rd sheet with the sums?
 
Upvote 0
It would be pretty simple to write but also dangerous. If you ran this over and over you keep adding your data cells value to the master over and over. Why not just make a 3rd sheet with the sums?

Hi Steve the Fish - I understand the concern, but that's kind of the idea.
Other people will be adding data to the Data01 sheet at intervals during the day(s), I want them to 'upload' the data when collected. After upload, I'll have the data in Data01 zero'd so fresh data can be added on the next cycle. Having a third sheet to sum the data means it will be a one off addition as opposed to a continuous collation of the data. I probably should have clarified that straight off.
Thanks
den
 
Upvote 0
See if this works for you. Test first on a copy workbook! Data01 workbook needs to be open.

Code:
Dim arr, arr2
Dim i As Long, j As Long

arr = Sheets("Sheet1").Range("C10:S63")
arr2 = Workbooks("Data01.xlsx").Sheets("Sheet1").Range("C10:S63")
For i = LBound(arr, 1) To UBound(arr, 1)
    For j = LBound(arr, 2) To UBound(arr, 2)
        arr(i, j) = arr(i, j) + arr2(i, j)
    Next
Next
Sheets("Sheet1").Range("C10:S63").Value = arr
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,992
Latest member
prabhuk279

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