danitouffaha
New Member
- Joined
- Nov 16, 2012
- Messages
- 18
Hi,
I have a need to disable F2 for certain cells based on a specific condition.
I have added this below to call customF2Fct when F2 is pressed
Now in customF2Fct
The escape works and I avoid the cell being open for editing, but if the condition is true, the sendKeys F2 does not open the cell for editing.
Instead it toggles the numLock.
Can you please help with what I am missing?
Thanks
Dani
I have a need to disable F2 for certain cells based on a specific condition.
I have added this below to call customF2Fct when F2 is pressed
VBA Code:
Application.OnKey "{F2}", "customF2Fct"
Now in customF2Fct
VBA Code:
Public Function customF2Fct()
Selection.Activate
'continue as F2 if the condition is met
If Condition = True Then
Application.SendKeys Keys:="{F2}"
Else
Application.SendKeys Keys:="{Esc}"
End If
DoEvents
End Function
The escape works and I avoid the cell being open for editing, but if the condition is true, the sendKeys F2 does not open the cell for editing.
Instead it toggles the numLock.
Can you please help with what I am missing?
Thanks
Dani