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?
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?