Placing of cursor is wrong

vishwajeet_chakravorty

Board Regular
Joined
Mar 8, 2010
Messages
120
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static OldCell As Range
Dim taborder As Variant
Dim i As Integer
If OldCell Is Nothing Then
Set OldCell = Range("E5")

End If
taborder = Array("E5", "E7", "E9", "E13", "E15", "E17", "E19", "E21", "E23", "E25", "E27", "E29", "E31", "E33", "E35", _
"J5", "J7", "J9", "J11", "J13", "J15", "J17", "J19", "J21", "J23", "J25", "J27", "J29", "J31", "J33", "J35")
Application.EnableEvents = False
On Error Resume Next
i = WorksheetFunction.Match(Target.Address(0, 0), taborder, False)
If Err = 0 Then
Set OldCell = ActiveCell
Application.EnableEvents = True
Exit Sub
Else
Err.Clear
End If
On Error GoTo 0
i = WorksheetFunction.Match(OldCell.Address(0, 0), taborder, False)
If i > UBound(taborder) Then
Range(taborder(0)).Select
Else
Range(taborder(i)).Select
End If
Set OldCell = ActiveCell
Application.EnableEvents = True
End Sub
I have written the taborder in a worksheet but acording to this the cursor should go to E5 in the begining but it goes to E7 when I press the enter. What is wrong in this code?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
That is most likely because the first element in your array ("E5") is taborder(0) not taborder(1)

Using "E5" as an example, Match will return a value of 1 when searching the taborder array, but taborder(1) does not return "E5", unless you have the code I describe below.

Try adding the blue line where shown
Rich (BB code):
Option Base 1

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

I haven't checked the rest of your code and the above change might necessitate other changes in your code.
 
Last edited:
Upvote 0
Yes now it is coming to E5 but the cursor getting fixed in E5 it is not going anywhere. Now what to do?
As I mentioned before:
I haven't checked the rest of your code and the above change might necessitate other changes in your code.
I am about to sign off for the night but you can put a BreakPoint in your code near the top of the code then when you move your cursor, step through the code a line at a time with F8 and you may get an idea of what is going wrong.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,736
Members
452,940
Latest member
Lawrenceiow

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