Application.OnKey "s"

AlbyDangles

New Member
Joined
Dec 14, 2013
Messages
6
I am running a macro by pressing the "s" key if the active cell is in column 3 and the row height is 31.5. That part is working OK.

My problem is I have to press the "s" key twice when a cell that is not in column 3 and the row height is 31.5 is selected.



Private Sub XL_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.OnKey "s", "Process_S_KeyEvent"
End Sub






Private Sub Process_S_KeyEvent()


If ActiveCell.Column = 3 And ActiveCell.RowHeight = 31.5 Then
MsgBox "Hello"

Exit Sub
Else
Application.OnKey "s" 'I think the problem is here
End If


End Sub
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,010
Office Version
  1. 2010
Platform
  1. Windows
see if this works...

Code:
Private Sub Process_S_KeyEvent()
    If ActiveCell.Column = 3 And ActiveCell.RowHeight = 31.5 Then
        MsgBox "Hello"
    Else
        MsgBox "not correct height or column"
    End If
End Sub
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
Dont forget to assign it, try this codes

jiuk

Code:
Sub JACKS_Apps_KEY_MY_RUN_IT()

'Written by Jack in the UK : For http://www.mrexcel.com/
'// Feed - /forum/excel-questions/602726-application-onkey-not-working.html
'// 30 Jan  2014

'// jiuk to "RUN IT"
Application.OnKey "^s", "Jacks TEST"

'// jiuk - NOTE .....
'// jiuk - Jacks test is a seperate macro that is called by "s"

End Sub
Code:
Sub Jacks_TURN_IT_OFF()
    Application.OnKey "^e"
End Sub
Code:
Sub Jacks_TEST_IT_WORKS()
MsgBox "Jack says it  A works" & _
vbCrLf & _
"Application Key S activated"

End Sub
 

AlbyDangles

New Member
Joined
Dec 14, 2013
Messages
6
Thanks for your reply diddi.
I need to get the "s" key to return to normal when my if statement is false.


Private Sub Process_S_KeyEvent() If ActiveCell.Column = 3 And ActiveCell.RowHeight = 31.5 Then MsgBox "Hello" Else make the "s" key work as normal End IfEnd Sub</pre>
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,782
Office Version
  1. 2010
Platform
  1. Windows
To return a key combination to the default,

Code:
application.onkey, "keycombination"
 

Watch MrExcel Video

Forum statistics

Threads
1,123,481
Messages
5,601,918
Members
414,482
Latest member
morkar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top