Adding one to the current value in a cell

  • Thread starter Thread starter mitchbryan
  • Start date Start date
M

mitchbryan

Hi,

I'm trying to set something up that enables me to press a button and
the numeric value in a cell will increase by one. I don't want this
cell to relate to another cell, just if, say, the value in the cell
was 1 and I pressed a key it would increase to 2 and if I pressed the
key again it would increase to 3 and so on...

Can anyone help me?

Mitch
 
Hi, try the following code snippet, cells(1,1).value = cells(1,1).value+1.
This will increment the value at row 1 and column 1 by 1. Include this
snippet within the code that will be called when a button is pressed.
 
right click sheet tab>view code>insert this>
Now, if you double click cell a5 or a6 the cell clicked will increase by
one. Is that what you want?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Address = "$A$5" Or Target.Address = "$A$6" Then
On Error GoTo fixit
Application.EnableEvents = False
If Target.Value = 0 Then oldvalue = 0
Target.Value = 1 * Target.Value + 1
oldvalue = Target.Value
fixit:
Application.EnableEvents = True
End If
Cancel = True
End Sub
 
Hi again,

Thankyou both for your help that's great and has solved my problem,

Mitch
 

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

Back
Top