Cell Format subtracting 1

W

Wendy

I would like to format a cell that each time a number is typed in it will
subtract 1 from that number. I do not want to put a formula in another colum
to do this, just when I type in a 5 for example the 5 would change to a 4.
Can this be done?
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then .Value = .Value - 1
End With
End If

ws_exit:
Application.EnableEvents = True
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



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

Bob Phillips

LOL! think of a number, and subtract 1.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Gord Dibben

Wendy

How about a Spinner from the Forms toolbar.

Then you could go down or up as you choose.


Gord Dibben MS Excel MVP
 
Top