![]() |
VBA: sum two named ranges, cell-by-cell
If I have x = A1:A4, y= B1:B4, z = C1:C4. Is there a way in a VBA script to do
z[i] = x[i] + y[i]? Thanks, George |
sum two named ranges, cell-by-cell
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" wrote in message ... If I have x = A1:A4, y= B1:B4, z = C1:C4. Is there a way in a VBA script to do z[i] = x[i] + y[i]? Thanks, George |
sum two named ranges, cell-by-cell
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" wrote in message ... 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" wrote in message ... If I have x = A1:A4, y= B1:B4, z = C1:C4. Is there a way in a VBA script to do z[i] = x[i] + y[i]? Thanks, George |
sum two named ranges, cell-by-cell
On Fri, 28 Apr 2006 16:21:14 -0500, "Chip Pearson" wrote:
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 |
All times are GMT +1. The time now is 07:13 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com