Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default keydown event

If you only need your key event in a one Workbook AND it's OK to delete or
to change the value of the cursor cell, maybe something like this:

Put the addition of cells in columns 2 & 3, of the row of the keypress, into
the cell that "p" was entered:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim nRow As Long, d As Double
On Error GoTo errH
If Target.Count = 1 And Target(1).Column 3 Then
If LCase(Target.Value) = ("p") Then
Application.EnableEvents = False
nRow = Target.Row
d = Cells(nRow, 2).Value + Cells(nRow, 3)
If d Then
Target.Value = d
Else: Target.Value = ""
End If
End If
End If

errH:
Application.EnableEvents = True
End Sub

This Worksheet_Change event goes in a Sheet module (right-click sheet tab
View code).
You could adapt to call your own macro:

Target.Value = "" ' delete the key press with Events disabled
MyMacro

If you want trap the key on all worksheets, change Worksheet_Change to
Workbook_SheetChange and put the code in the ThisWorkbook module.

Regards,
Peter T

"bfa" wrote in message
...
Hello

Im trying to catch a keydown event on a worksheet. If i press on my
worksheet any key it should response like an event. How can I make it?
I found a lot of examples with controls, but no one on a worksheet.

thnx



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
KeyDown event on form Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 0 October 26th 07 03:30 PM
keydown event K Dales[_2_] Excel Programming 0 April 18th 05 12:46 PM
user form-on open event? keydown event? FSt1[_3_] Excel Programming 2 August 5th 04 02:26 PM
KeyDown event in sheet Peter Wallin Excel Programming 1 February 27th 04 10:25 AM
keydown event jim c. Excel Programming 1 October 10th 03 03:16 AM


All times are GMT +1. The time now is 07:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"