I have a block of cells on my Excel worksheet that I have attached scroll bars to. The scroll bars work fine, but one of my users asked if he could activate the scroll function by pressing the downarrow in the last row, the uparrow in the top row, etc.
I keyed it to the Worksheet_SelectionChange event as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Test for edges of scrolling areas
'Expanded Input zone
If ActiveCell.row = 31 And (ActiveCell.Column >= 3 And ActiveCell.Column <= 16) Then
'check for uparrow movement
Application.OnKey "{UP}", Scroll_VBayPurlin(-1)
Application.OnKey "{UP}"
Else
Application.OnKey "{UP}"
End If
(Similar for other 3 directions)
This logic works in the sense that when I first enter the cell moving with an arrow key from an adjacent cell, it will do the scroll.
I have two problems:
1) It doesn't seem to make any difference which key (or mouse process)I used to get to the cell, the scroll activates. It is almost like I have an OnKey "ANY" if such existed. Because each of the OnKey calls activates regardless of the key pressed, I actually scroll both horizontally and vertically in sequence when I move into a corner cell of the scroll area. How does one get the OnKey procedure to recognize only the specified key activity and ignore the process if it is not the correct key.
2) Because it runs off the SelectionChange event the scroll only happens once unless I move out of the cell and back in again. A second arrow click moves the ActiveCell to the adjacent cell. Using the opposing arrow to move back into the scroll area activates the scroll once again (in the opposite direction of the actual arrow key that I pressed).
Any suggestions so that I can do multiple arrow keystrokes simultaneously within a single cell.
I appreciate any insights you might give me.
Thanks.
I keyed it to the Worksheet_SelectionChange event as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Test for edges of scrolling areas
'Expanded Input zone
If ActiveCell.row = 31 And (ActiveCell.Column >= 3 And ActiveCell.Column <= 16) Then
'check for uparrow movement
Application.OnKey "{UP}", Scroll_VBayPurlin(-1)
Application.OnKey "{UP}"
Else
Application.OnKey "{UP}"
End If
(Similar for other 3 directions)
This logic works in the sense that when I first enter the cell moving with an arrow key from an adjacent cell, it will do the scroll.
I have two problems:
1) It doesn't seem to make any difference which key (or mouse process)I used to get to the cell, the scroll activates. It is almost like I have an OnKey "ANY" if such existed. Because each of the OnKey calls activates regardless of the key pressed, I actually scroll both horizontally and vertically in sequence when I move into a corner cell of the scroll area. How does one get the OnKey procedure to recognize only the specified key activity and ignore the process if it is not the correct key.
2) Because it runs off the SelectionChange event the scroll only happens once unless I move out of the cell and back in again. A second arrow click moves the ActiveCell to the adjacent cell. Using the opposing arrow to move back into the scroll area activates the scroll once again (in the opposite direction of the actual arrow key that I pressed).
Any suggestions so that I can do multiple arrow keystrokes simultaneously within a single cell.
I appreciate any insights you might give me.
Thanks.