View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Héctor Miguel Héctor Miguel is offline
external usenet poster
 
Posts: 434
Default What key was pressed?

hi, Ken !

... detect which key the user pressed when entering a cell value?...
... check... entered value is not greater than... row 4... same column without using data validation.
... I'm presently using... Workbook_SheetChange Event
... but it only works properly when the user... selects the cell directly below...
... want to... cover instances where the user uses tab, up arrow, left arrow, right arrow or enter...
... need to determine the key pressed by the user.


I'm not quite sure I'm following you properly, but...
don't forget IF the user selects directly another sheet-tab
you may want to give a try into same event with code like this [modify as needed]...
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Row = 4 Then Exit Sub
If Application.IsText(Target) Then Exit Sub
If Application.IsText(Sh.Cells(4, Target.Column)) Then Exit Sub
If Target Sh.Cells(4, Target.Column) Then
MsgBox "Value in " & Sh.Name & "!" & Target.Address & " *must NOT*" & vbCr & _
"be greater than " & Sh.Name & "!" & Sh.Cells(4, Target.Column).Address
Application.Undo
End If
End Sub

hth,
hector.