I have two 3x3 (for simplicity's sake) ranges of cells; all cells in
each range contain plain ol' integers. I want to add the values of the
cells in Range A to the values of the cells in Range B and have the
sums become the new values of the cells in Range A.
I am learning VBA 'by ear' so I'm not very good, but long ago I
figured I could perform such an operation with SINGLE cells simply by
something like:
Range("A1").Value = Range("A1").Value + Range("A2").Value
However, when I made Range reference multiple cells...
Range("A1:C3").Value = Range("A1:C3").Value + Range("A4:C6").Value
...I got a type mismatch.
I then figured out that I could use Copy and PasteSpecial(xlValues) to
attain the desired effect, but in practice the ranges are large and
the calculations are repeated hundreds of times. This abuse of the
clipboard really wreaks havoc on system performance and I'm sure
there's a better way to do it.
I'd like specific examples of VBA code that would help me accomplish
the seemingly simple task of adding two ranges together. I imagine
there's more than one solution, and I'd like to see all possibilities,
but obviously the most streamlined approaches are preferred.
By the way, another thing that's been bugging me is the redundancy in
my examples. If you can show me a way to add two values without
mentioning the 'destination' range twice, I'd gladly toss in an extra
few bucks.
Thanks. |