Link to home
Start Free TrialLog in
Avatar of allenkent
allenkentFlag for United States of America

asked on

Excel Macro to start cursor at a specific field

I am using the following code to tab from F to G. Then it goes down to F then G again and so on and so on. I am just entering data into the F and G field. What i need is when open the cursor automatically starts at F6. Here is my code. Can I add anything to start at F6?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Column > 7 Then
     Application.EnableEvents = False
     Target.Offset(1, -Target.Column + 6).Select
     Application.EnableEvents = True
End If
End Sub

Avatar of point_pleasant
point_pleasant
Flag of United States of America image

try
Range("F6").Select
I just tested this and it worked for me:

Option Explicit

Private Sub Workbook_Open()
     Range("F6").Select
End Sub

Open in new window

Avatar of allenkent

ASKER

I tried plugging in and get errors. Here is my code. Do I put the F6 after the word range?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Column > 7 Then
     Application.EnableEvents = False
     Target.Offset(1, -Target.Column + 6).Select
     Application.EnableEvents = True
End If
End Sub
Using the code I put above (you can exclude the Option Explicit), once you open your Workbook, the cell F6 will be selected. It's using the Open action of the Workbook to trigger the F6 cell selection.
What about my code? I need both things to happen. When I put both codes I get an error. I need it to open at F6 and only go from F to G on tabs.
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Range("F6").Select
If Target.Column > 7 Then
     Application.EnableEvents = False
     Target.Offset(1, -Target.Column + 6).Select
     Application.EnableEvents = True
End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of yobri
yobri
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Point Pleasant code does not let me go anywhere except F6. It always stays in F6
Yobri code does not start in F6 but instead it opens in A41 everytime.

not seeing the code beore the sub call


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)


i would suggest you move the

Range("F6").Select


before the call is made to your sub


Could you try closing Excel entirely and then relaunching it? That Workbook_Open sub really should leave no other option but to select cell F6 at open...