Worksheet Summation and Column multiplication

NewToVBA1

New Member
Joined
May 22, 2011
Messages
20
Hi All,
I have two problem and I could not figure it out by my own nor with by searching the net.

Problem1: I need a VBA macro to add respective cells of two identical worksheets, but with different data, and paste it in a third worksheet. The number of rows with available data will change with time, so I need the code to search the available data and do the addition.

Problem2: I need another code to multiply cells of one column from one worksheet to multiply with another column with another worksheet and paste the resulting column in a third worksheet. Here also, the rows with available data will change with time, so I need the code to search the available data and do the addition.


I am under pressure to complete the work but I did not realise that I it will be so complicated. Thanks in advance for the help.


Regards:confused:
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If your 3 sheets are named "a", "b" and "c" respectively then you should be able to add values of corresponding cells on "a" and "b" and put the results in corresponding cells in sheet "c" by the following code
Code:
Sub addem()
Dim lrw&, lcl&, i&, j&
Dim aa, bb, cc()
With Sheets("a")
    lrw = .Cells.SpecialCells(11).Row
    lcl = .Cells.SpecialCells(11).Column
    aa = .Cells(1).Resize(lrw, lcl)
End With
With Sheets("b")
    bb = .Cells(1).Resize(lrw, lcl)
End With
ReDim cc(1 To lrw, 1 To lcl)
For i = 1 To lrw
    For j = 1 To lcl
        cc(i, j) = aa(i, j) + bb(i, j)
Next j, i
Sheets("c").Cells(1).Resize(lrw, lcl) = cc
End Sub

You can do something on similar lines if multiplying columns.
 
Upvote 0
Hi,

Thanks for your feedback.

Probably somewhat briefer and faster is this non-looping one, using named ranges
Code:
Sub addem2()
Dim lrw&, lcl&
With Sheets("a")
    lrw = .Cells.SpecialCells(11).Row
    lcl = .Cells.SpecialCells(11).Column
    .Cells(1).Resize(lrw, lcl).Name = "aa"
End With
With Sheets("b")
    .Cells(1).Resize(lrw, lcl).Name = "bb"
End With
Sheets("c").Cells(1).Resize(lrw, lcl) = Evaluate("=(aa+bb)")
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

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