ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Funtion that adds two named ranges (https://www.excelbanter.com/excel-programming/353492-funtion-adds-two-named-ranges.html)

Matt

Funtion that adds two named ranges
 
I have the following:

Named ranges within columns A & C (ie A1:A10 is named "Calc" and C1:C10 is
named "Total"). Column A contains a formula that calculates a value based on
fixed data and data entered into column B by a user.

I would like a function that captures the current value of a cell in Column
A and the value of the corresponding cell in Column C. I want these two
values added together and have the new value placed back into Column C. This
function should only act against the selected cells within the range.

Here is an example of what I would like to do:

Column A Column B Column C
1 10 4 0
2 20 3 10
3 40 5 5
4 20 1 20
5 30 5 8
etc..

If Cells C1, C3 & C4 are selected and the function is run, the resulting
values should be: C1 = 10 (A1 + C1), C3 = 45 (A3 + C3), & C4 = 40 (A4 + C4).


Anybody want to give this one a shot?

Thanks

Matt

Tom Ogilvy

Funtion that adds two named ranges
 
Sub AdjustTotal()

set selection = intersect(Range("Calc"),Selection.EntireRow)
for each cell in Selection
cell.offset(0,2).Value = cell + cell.offset(0,2).Value
Next
End Sub

--
Regards,
Tom Ogilvy



"Matt" wrote in message
...
I have the following:

Named ranges within columns A & C (ie A1:A10 is named "Calc" and C1:C10 is
named "Total"). Column A contains a formula that calculates a value based

on
fixed data and data entered into column B by a user.

I would like a function that captures the current value of a cell in

Column
A and the value of the corresponding cell in Column C. I want these two
values added together and have the new value placed back into Column C.

This
function should only act against the selected cells within the range.

Here is an example of what I would like to do:

Column A Column B Column C
1 10 4 0
2 20 3 10
3 40 5 5
4 20 1 20
5 30 5 8
etc..

If Cells C1, C3 & C4 are selected and the function is run, the resulting
values should be: C1 = 10 (A1 + C1), C3 = 45 (A3 + C3), & C4 = 40 (A4 +

C4).


Anybody want to give this one a shot?

Thanks

Matt




Matt

Funtion that adds two named ranges
 
Thanks Tom...was able to use a variation of what you gave to get what I
needed.

"Tom Ogilvy" wrote:

Sub AdjustTotal()

set selection = intersect(Range("Calc"),Selection.EntireRow)
for each cell in Selection
cell.offset(0,2).Value = cell + cell.offset(0,2).Value
Next
End Sub

--
Regards,
Tom Ogilvy



"Matt" wrote in message
...
I have the following:

Named ranges within columns A & C (ie A1:A10 is named "Calc" and C1:C10 is
named "Total"). Column A contains a formula that calculates a value based

on
fixed data and data entered into column B by a user.

I would like a function that captures the current value of a cell in

Column
A and the value of the corresponding cell in Column C. I want these two
values added together and have the new value placed back into Column C.

This
function should only act against the selected cells within the range.

Here is an example of what I would like to do:

Column A Column B Column C
1 10 4 0
2 20 3 10
3 40 5 5
4 20 1 20
5 30 5 8
etc..

If Cells C1, C3 & C4 are selected and the function is run, the resulting
values should be: C1 = 10 (A1 + C1), C3 = 45 (A3 + C3), & C4 = 40 (A4 +

C4).


Anybody want to give this one a shot?

Thanks

Matt






All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com