+ Reply to Thread
Results 1 to 3 of 3

Funtion that adds two named ranges

Hybrid View

  1. #1
    Matt
    Guest

    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

  2. #2
    Tom Ogilvy
    Guest

    Re: 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" <Matt@discussions.microsoft.com> wrote in message
    news:47A02692-51EE-4FD9-B616-DA3174EA7922@microsoft.com...
    > 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




  3. #3
    Matt
    Guest

    Re: 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" <Matt@discussions.microsoft.com> wrote in message
    > news:47A02692-51EE-4FD9-B616-DA3174EA7922@microsoft.com...
    > > 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

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1