why wont this code to tab work

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,

All I'm trying to do is control what is the next cell selected after you press tab, enter etc.

I have this code i've used before but it wont work, I'm sure I'm missing something

can anyone help with what I'm doing wrong (feel free to change, rewrite or just give better options)

To summaries i just want to select the next cell in the sequence show below when you press tab or enter etc.

please help if you can

Thanks

tony
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Tony, it might help if you post the code ;)
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("E8:G14")) Is Nothing Then

           Application.OnKey "{TAB}", "Testing"
           Application.OnKey "{ENTER}", "Testing"
           Application.OnKey "~", "Testing"

'Exit Sub
End If
      

If Not Intersect(Target, Range("Q8:Q27")) Is Nothing Then

           Application.OnKey "{TAB}", "Testing2"
           Application.OnKey "{ENTER}", "Testing2"
           Application.OnKey "~", "Testing2"

'Exit Sub
End If
END SUB


Sub Testing()

seq = Array("$E$8:$F$8", "$G$8", "$E$11:$F$11", "$G$11", "$E$14:$F$14")
For i = 0 To 4
    If Selection.Address = seq(i) Then
        If i < 4 Then
        Range(seq(i + 1)).Select
        Else
        Range(seq(0)).Select
        End If
        Exit For
    End If
Next i

End Sub


Sub Testing2()

seq = Array("$Q$8", "$Q$9", "$Q$10", "$Q$11", "$Q$16", "$Q$17", "$Q$19", "$Q$24", "$Q$25", "$Q$26", "$Q$27")
For i = 0 To 10
    If Selection.Address = seq(i) Then
        If i < 10 Then
        Range(seq(i + 1)).Select
        Else
        Range(seq(0)).Select
        End If
        Exit For
    End If
Next i
            
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top