+ Reply to Thread
Results 1 to 6 of 6

Loop to add +1 in cell?

  1. #1
    Registered User
    Join Date
    06-06-2006
    Posts
    3

    Loop to add +1 in cell?

    Hello,

    What I want is a button that will add 1 to a number everytime it is pressed. Can you guys give me any help? Thanks

  2. #2
    Don Guillett
    Guest

    Re: Loop to add +1 in cell?

    right click sheet tab>view code>insert this

    Option Explicit
    Dim oldvalue As Double
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$A$5" Or Target.Address = "$B$5" Then
    Application.EnableEvents = False
    If Target.Value = 0 Then oldvalue = 0
    Target.Value = 1 + oldvalue
    oldvalue = Target.Value
    Application.EnableEvents = True
    End If
    End Sub
    Sub fixit()
    Application.EnableEvents = True
    End Sub


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "bxvang" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hello,
    >
    > What I want is a button that will add 1 to a number everytime it is
    > pressed. Can you guys give me any help? Thanks
    >
    >
    > --
    > bxvang
    > ------------------------------------------------------------------------
    > bxvang's Profile:
    > http://www.excelforum.com/member.php...o&userid=35135
    > View this thread: http://www.excelforum.com/showthread...hreadid=548932
    >




  3. #3
    Registered User
    Join Date
    06-06-2006
    Posts
    3
    Okay, so what that code does is...

    2 cells A5 and B5

    You click on either cell and it adds +1 to the previous number in the cell.

    Is there a way to assign that code to a button? Thanks for your help. It is much appreciated.

  4. #4
    Jeff Standen
    Guest

    Re: Loop to add +1 in cell?

    Range("a1").value=range("a1").value + 1

    Is that what you mean?

    Jeff

    "bxvang" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Okay, so what that code does is...
    >
    > 2 cells A5 and B5
    >
    > You click on either cell and it adds +1 to the previous number in the
    > cell.
    >
    > Is there a way to assign that code to a button? Thanks for your help.
    > It is much appreciated.
    >
    >
    > --
    > bxvang
    > ------------------------------------------------------------------------
    > bxvang's Profile:
    > http://www.excelforum.com/member.php...o&userid=35135
    > View this thread: http://www.excelforum.com/showthread...hreadid=548932
    >




  5. #5
    Registered User
    Join Date
    06-06-2006
    Posts
    3
    Yes, it works perfectly. Thanks!

    For reference, here is another code that does the same thing.

    Sub add_one()

    With Activesheet.Range("A1")
    .Value = .Value + 1
    End With

    End Sub

  6. #6
    Don Guillett
    Guest

    Re: Loop to add +1 in cell?

    not without another dot

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "bxvang" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Yes, it works perfectly. Thanks!
    >
    > For reference, here is another code that does the same thing.
    >
    > Sub add_one()
    >
    > With Activesheet.Range("A1")
    > Value = .Value + 1
    > End With
    >
    > End Sub
    >
    >
    > --
    > bxvang
    > ------------------------------------------------------------------------
    > bxvang's Profile:
    > http://www.excelforum.com/member.php...o&userid=35135
    > View this thread: http://www.excelforum.com/showthread...hreadid=548932
    >




+ 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