Thread: Macro
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Macro

If by "within a cell" you mean in Edit Mode, then no - macros are
disabled in Edit mode.

If you want this to happen in one particular cell, this may work for you:

Put this in the worksheet code module:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.OnKey "{UP}"
Application.OnKey "{DOWN}"
With Target
If .Count = 1 Then
If Not Intersect(.Cells, Range("J5")) Is Nothing Then
Application.OnKey "{UP}", "AddOne"
Application.OnKey "{DOWN}", "SubtractOne"
End If
End If
End With
End Sub

(change J5 to suit). Put these in a regular code module:

Public Sub AddOne()
With ActiveCell
If IsNumeric(.Value) Then .Value = .Value + 1
End With
End Sub

Public Sub SubtractOne()
With ActiveCell
If IsNumeric(.Value) Then .Value = .Value - 1
End With
End Sub



In article .com,
wrote:

I am trying to create a macro-and I am new at this so bare with me-
where if I am within a cell by simply pushing the up or down arrow the
value within the cell will increase or decrease with each key stroke.
Can this be done.