Thread: Macro
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Macro

You can remove the "On Error GoTo 0" line in the IncrementCell macro. A
leftover when I changed my mind on how to deal with the potential of text in
the cells.

Greg

"Greg Wilson" wrote:

Run the first macro to add a button to the Worksheet Menu Bar that toggles
the behavior of the arrow keys. This button will be temporary and so will
automatically delete upon closing Excel. After adding the button click it and
then test the arrow keys. Click it again to reset to normal.

Sub AddBtn()
With Application.CommandBars(1)
With .Controls.Add(Temporary:=True)
.OnAction = "TogArrowKeys"
.FaceId = 468
End With
End With
End Sub

Sub TogArrowKeys()
Dim btn As CommandBarButton
With Application
Set btn = .CommandBars.ActionControl
If btn.State = msoButtonUp Then
.OnKey "{UP}", "IncrementCell"
.OnKey "{DOWN}", "DecrementCell"
btn.State = msoButtonDown
Else
.OnKey "{UP}"
.OnKey "{DOWN}"
btn.State = msoButtonUp
End If
End With
End Sub

Sub IncrementCell()
With ActiveCell
If Not IsNumeric(.Value) Then Exit Sub
.Value = .Value + 1
End With
On Error GoTo 0
End Sub

Sub DecrementCell()
With ActiveCell
If Not IsNumeric(.Value) Then Exit Sub
.Value = .Value - 1
End With
End Sub

Regards,
Greg