Cursor skip over a cell

M

mikeburg

Help. Working on some simple sheet VBA code to:

(1) skip over a cell from the cell above using enter, tab, or arrow
and

(2) skip over a cell from the cell below using the up arrow

I have the following code that works from above:

'SECTION TO JUMP FROM CELL F16 TO G 19 (skip F17:G18)
If Target.Address = "$F$17:$G$18" Then Target(3, 2).Select


Can someone help me add the code to skip cells F17:G18 when I up arrow
from the cell below? Thanks, mikeburg
 
G

Guest

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Skips over range F17:G17 if moved into from directly above or directly below
' static variable used to keep track of where we moved from:
Static CameFrom As String
' Check to see if we moved into the designated range
If Not (Intersect(Target, Range("F17:G18")) Is Nothing) Then
' Now check to see where we came from:
Select Case CameFrom
Case "$F$16", "$G$16"
Range("G19").Select ' if from cells above, move below
Case "$F$19", "$G$19"
Range("F16").Select ' if from cells below, move above
End Select
CameFrom = Selection.Address
Else
CameFrom = Target.Cells(1, 1).Address
End If
' Note how CameFrom is reset toward the end of the sub to
' keep use the new selection as CameFrom next time we move
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top