+ Reply to Thread
Results 1 to 3 of 3

count how many times a button is pressed

  1. #1
    Mike
    Guest

    count how many times a button is pressed

    Hi i am using excel to print out cells from a form button using this macro
    "ActiveSheet.Range("a8:b8").PrintOut preview:=False" is there a way i can
    modify it to count how many times the button is pressed and that amount shown
    in an adjecent cell please
    --
    thanks

  2. #2
    Paul B
    Guest

    Re: count how many times a button is pressed

    Mike, you could add a line of code to your macro like this, will add 1 to
    sheet1 range A1 each time it is run

    Sheets("Sheet1").Range("A1").Value = _
    Sheets("Sheet1").Range("A1").Value + 1


    --
    Paul B
    Always backup your data before trying something new
    Please post any response to the newsgroups so others can benefit from it
    Feedback on answers is always appreciated!
    Using Excel 2002 & 2003

    "Mike" <[email protected]> wrote in message
    news:[email protected]...
    > Hi i am using excel to print out cells from a form button using this macro
    > "ActiveSheet.Range("a8:b8").PrintOut preview:=False" is there a way i

    can
    > modify it to count how many times the button is pressed and that amount

    shown
    > in an adjecent cell please
    > --
    > thanks




  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Mike,

    Add this code to a VBA module in your workbook. It will place the number of times the button has been pushed in the cell to the right of the button and then call the print function.

    ______________________________
    Public Sub ButtonCount()

    Dim Col As Long
    Dim Row As Long

    With ActiveSheet.Shapes(Application.Caller)
    Row = .TopLeftCell.Row
    Col = .BottomRightCell.Column
    End With

    With Cells(Row, Col)
    .Value = .Value + 1
    End With

    ActiveSheet.Range("a8:b8").PrintOut preview:=False
    End Sub
    ______________________________

    Sincerely,
    Leith Ross

+ 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