VBA: sum two named ranges, cell-by-cell

  • Thread starter Thread starter George
  • Start date Start date
G

George

If I have x = A1:A4, y= B1:B4, z = C1:C4. Is there a way in a VBA script to do
z = x + y?

Thanks,
George
 
George,

Try some code like the following:

Dim Ndx As Long
Dim Result As Double
For Ndx = 1 To Range("X").Rows.Count
Result = Range("X")(Ndx) + Range("Y")(Ndx) + Range("Z")(Ndx)
Debug.Print Result
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
George,

I misread your post. Try the following code instead.

Dim Ndx As Long
For Ndx = 1 To Range("X").Rows.Count
Range("Z")(Ndx) = Range("X")(Ndx) + Range("Y")(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



Chip Pearson said:
George,

Try some code like the following:

Dim Ndx As Long
Dim Result As Double
For Ndx = 1 To Range("X").Rows.Count
Result = Range("X")(Ndx) + Range("Y")(Ndx) + Range("Z")(Ndx)
Debug.Print Result
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


George said:
If I have x = A1:A4, y= B1:B4, z = C1:C4. Is there a way in a
VBA script to do
z = x + y?

Thanks,
George

 
George,

I misread your post. Try the following code instead.

Dim Ndx As Long
For Ndx = 1 To Range("X").Rows.Count
Range("Z")(Ndx) = Range("X")(Ndx) + Range("Y")(Ndx)
Next Ndx

That's nice - thank you.

George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top