I just created a dummy UserForm with a RefEdit, and I see that the arrow keys work in conjunction with Shift and Ctrl as expected, but only if the UserForm hasn't been shrunken to show only the RefEdit.
I've used the _KeyDown
event in a UserForm to capture when a user clicks the keyboard arrow keys. Maybe you could try the _KeyDown
event of the RefEdit.
Private Sub RefEdit1_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
End Sub
It's going to be pretty complicated, because you're coing to have to see what's indicated in the RefEdit, and what was initially in the RefEdit, so you know whetehr the arrow keys expand or shrink the range in a particular direction.
A further complication is that a RefEdit_KeyDown
is different from other _KeyDown
events. _KeyDown
for a textbox looks like this:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
End Sub
Notice that KeyCode is of type MSForms.ReturnInteger
, while in the RefEdit, it is type Integer
. What's that mean? Well, the arrow keys Left, Up, Right, and Down have ReturnInteger values of 37, 38, 39, and 40. These keys have Integer values of 0, 0, 0, and 0. So using KeyCode As Integer
, the RefEdit can't distinguish which arrow key was clicked (or which other value=0 keys may have been clicked, if they exist).
If you try to change the RefEdit1_KeyDown
event to use ReturnInteger
, you get a compile error. And if the RefEdit has focus, it receives the _KeyDown
event, so you can't use _KeyDown
for any other control to determine which arrow was clicked.
I don't use RefEdits in mission-critical projects. It is simply too flaky. Sometimes it doesn't even appear in UserForms on some users' computers, and often it just behaves in a flaky way. I've described a different approach in Alternative to Excel's Flaky RefEdit Control. That approach also does not support the arrow keys.