Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

VBA question

0

In excel, I have a VBA program that runs when ever I enter text in column A. In column B, it records the date and time stamp when it there is text there. I need the cursor to move to column C automatically after the date and time stamp. How can this be accomplished?

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("A2:A1000")) Is Nothing Then

        With Target(1, 2)

        .Value = Now

        .EntireColumn.AutoFit

Code_Goes_Here
         End With

    End If

End Sub

Answer
Discuss

Answers

0
Selected Answer

Zac

You haven't attached your macro or your file so I guess your macro is triggered by the Worksheet_change event. In that case, before End Sub, add:

Cells(Target.Row, 3).Select

Hope this is what you wanted. 

Discuss

Discussion

Private Sub Worksheet_Change(ByVal Target As Range)     If Target.Cells.Count > 1 Then Exit Sub     If Not Intersect(Target, Range("A2:A1000")) Is Nothing Then         With Target(1, 2)         .Value = Now         .EntireColumn.AutoFit          End With     End If End Sub
Zac (rep: 2) Dec 18, '21 at 4:13 pm
Zac. Thanks for selecting my Answer (I assume it fixed your problem - you didn't say- but if not, you just need to add a new line immediately before End Sub and paste the code in my Answer. If you click Select All above the line, it will be copied to your clipboard) 
John_Ru (rep: 6142) Dec 18, '21 at 4:25 pm
Add to Discussion
0

I applied the answer that was given to my question! It works

Now, I need it to jump down to the next open cell in Row 1 after I've entered text in Row 7

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("A2:A1000")) Is Nothing Then

        With Target(1, 2)

        .Value = Now

        .EntireColumn.AutoFit

        Cells(Target.Row, 3).Select

         End With

    End If

End Sub

Discuss

Discussion

Zac. Glad it worked (even though you put it in a With loop rather than after it).

You're asking a fresh question now (so needs a new one - with a descriptive title - since this is meant to be a Q&A forum not a discussion forum). You also need to clarify what the sentence starting "Now ..." means, without your file I'm not clear. 

Note too that an Answer should be a solution to a problem, not a reply or question extension. 
John_Ru (rep: 6142) Dec 18, '21 at 4:39 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login