+ Reply to Thread
Results 1 to 3 of 3

macro for auto sum

  1. #1
    ahemani
    Guest

    macro for auto sum

    I am fairly new to macros in general. Does anyone have an existing macro
    that I can use which will auto sum the existing value in a cell with a new
    value added to it......i.e. if cell B10 has a value in it of 55 and I type in
    5 into cell B10 it will auto sum and leave 60 as the new cell contents ?
    the actual code would really help...or just steps to do this.
    thanks


  2. #2
    Bob Phillips
    Guest

    Re: macro for auto sum

    Option Explicit

    Private prevValue

    Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    With Target
    If .Address = "$B$6" Then
    .Value = prevValue + .Value
    End If
    prevValue = .Value
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
    If .Address = "$B$6" Then
    prevValue = .Value
    End If
    End With
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "ahemani" <[email protected]> wrote in message
    news:[email protected]...
    > I am fairly new to macros in general. Does anyone have an existing macro
    > that I can use which will auto sum the existing value in a cell with a new
    > value added to it......i.e. if cell B10 has a value in it of 55 and I type

    in
    > 5 into cell B10 it will auto sum and leave 60 as the new cell contents ?
    > the actual code would really help...or just steps to do this.
    > thanks
    >




  3. #3
    Gord Dibben
    Guest

    Re: macro for auto sum

    Can be done as Bob points out, but do you really want to do this?

    Where is your "paper trail" so's you can keep track of entries?

    What do you do when someone enters 9 instead of 10?

    If you want to have an accumulator cell.....lotsa luck.


    Gord Dibben Excel MVP

    On Wed, 27 Jul 2005 22:09:01 -0700, "ahemani"
    <[email protected]> wrote:

    >I am fairly new to macros in general. Does anyone have an existing macro
    >that I can use which will auto sum the existing value in a cell with a new
    >value added to it......i.e. if cell B10 has a value in it of 55 and I type in
    >5 into cell B10 it will auto sum and leave 60 as the new cell contents ?
    >the actual code would really help...or just steps to do this.
    >thanks



+ 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