Excel VBA help

  • Thread starter Thread starter tmobccr2
  • Start date Start date
T

tmobccr2

Greetings. I am trying to add a simple (or so it would seem) script
to an excel workbook, and having spent the weekend trying to find how,
am now turning to this group for help. I have created a command
button in a worksheet. I need this button to keep a tally, so to
speak. Essentially, I have one cell that is going to increase in
value by a factor of one each time the button is clicked. So, as an
example, cell B18 = 1. Command Button is clicked once, B18 now equals
2, etc. Can this be done via VB in excel? It would seem simple to
do, but I am stumped. Any help is appreciated. Thanks!
 
Sub Button1_Click()
With ActiveSheet.Range("B18")
.Value = .Value + 1
End With
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Greetings. I am trying to add a simple (or so it would seem) script
to an excel workbook, and having spent the weekend trying to find how,
am now turning to this group for help. I have created a command
button in a worksheet. I need this button to keep a tally, so to
speak. Essentially, I have one cell that is going to increase in
value by a factor of one each time the button is clicked. So, as an
example, cell B18 = 1. Command Button is clicked once, B18 now equals
2, etc. Can this be done via VB in excel? It would seem simple to
do, but I am stumped. Any help is appreciated. Thanks!

It should be simple. How did you create the button?
--ron
 
Have you looked at using a simple Spinner button from the Forms Toolbar?


Gord Dibben MS Excel MVP
 
Try this. Right click sheet tab>view code>insert this. Works on double_click
of cell b18 only

Option Explicit
Dim oldvalue As Double

Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, Cancel As
Boolean)
On Error GoTo fixit
Application.EnableEvents = False
if target.address<>"$B$18" then exit sub
If target.Value = 0 Then oldvalue = 0
target.Value = 1 + oldvalue
oldvalue = target.Value
fixit:
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top