Hello Everyone!
I've got a set of merged cells that users will paste into. To bypass the error when pasting into merged cells, I wrote the following code:
This code makes it such that when you click a cell in the specified range, it will send the F2 key-press (similar to double clicking a cell), thereby bypassing the problem with pasting into merged cells.
The problem is, as I'm sure many are aware, SendKeys is bugged. It will toggle Caps Lock, NumLock, Scroll Lock on/off when activated. I've been looking for a solution to this for some time, but have been unable to find anything that works. I've tried using some of the code found online that finds the keystate of numlock and if off, turn it on. However, I cannot seem to get this code to work (I am somewhat new to VBA, so it's possible I'm doing something wrong).
So, I'm looking for a way to resolve this. I either need some code that works similar to sending the F2 keypress without actually using SendKeys. Or I need to find a functional method of finding the keystate of numlock and turning it on when it inevitably gets turned off (or possibly reset it to it's initial state (on or off) before the SendKeys macro activates).
Interesting side note. I did some experimentation on this. If I open my workbook with number lock turned on and then click in the given range B25:B50, number lock toggles off. If I then activate macro:
while number lock is turned off, it then turns number lock back on. Following that, subsequent activations of the macro that sends the F2 keypress do not toggle number lock. I've tried some experimentation with duplicating this with a macro that activates when the workbook is first opened, but I've yet to see success here.
Anyhow, any and all help on this matter is appreciated!
I've got a set of merged cells that users will paste into. To bypass the error when pasting into merged cells, I wrote the following code:
Code:
Private Sub Worksheet_Selectionchange(ByVal Target As Range) If Not Intersect(Target, Range("B25:B50")) Is Nothing Then
Application.SendKeys keys:="{F2}"
End If
End Sub
This code makes it such that when you click a cell in the specified range, it will send the F2 key-press (similar to double clicking a cell), thereby bypassing the problem with pasting into merged cells.
The problem is, as I'm sure many are aware, SendKeys is bugged. It will toggle Caps Lock, NumLock, Scroll Lock on/off when activated. I've been looking for a solution to this for some time, but have been unable to find anything that works. I've tried using some of the code found online that finds the keystate of numlock and if off, turn it on. However, I cannot seem to get this code to work (I am somewhat new to VBA, so it's possible I'm doing something wrong).
So, I'm looking for a way to resolve this. I either need some code that works similar to sending the F2 keypress without actually using SendKeys. Or I need to find a functional method of finding the keystate of numlock and turning it on when it inevitably gets turned off (or possibly reset it to it's initial state (on or off) before the SendKeys macro activates).
Interesting side note. I did some experimentation on this. If I open my workbook with number lock turned on and then click in the given range B25:B50, number lock toggles off. If I then activate macro:
Code:
Sub Button99_Click()
SendKeys "{NUMLOCK}"
End Sub
while number lock is turned off, it then turns number lock back on. Following that, subsequent activations of the macro that sends the F2 keypress do not toggle number lock. I've tried some experimentation with duplicating this with a macro that activates when the workbook is first opened, but I've yet to see success here.
Anyhow, any and all help on this matter is appreciated!