Cursor stuck in active cell

anvs

New Member
Joined
Apr 18, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Thanks to Mario_R for his code
'------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim w
If Target.Column > 1 Then Exit Sub
Application.EnableEvents = False
w = Target: Application.Undo
If w <> Target Then
Target = w
If Target(, 2) = "" Then Target(, 2) = Now Else Target(, 3) = Now
End If
Application.EnableEvents = True
End Sub
'------------------------------------------------- --
Work fine!
But, after ENTER - only in Col A after confirming data entry - the cursor remains in the same cell. It only jumps to the next cell after the second ENTER.
Is it possible to release the cursor, please?
Grateful
anvs
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Yes, it is possible to release the cursor after data entry in column A by modifying the code. You can add the line SendKeys "{TAB}" after the line If Target(, 2) = "" Then Target(, 2) = Now Else Target(, 3) = Now. This will simulate pressing the TAB key, which will release the cursor and move it to the next cell.

The modified code would look like this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim w
    If Target.Column > 1 Then Exit Sub
    Application.EnableEvents = False
    w = Target: Application.Undo
    If w <> Target Then
        Target = w
        If Target(, 2) = "" Then
            Target(, 2) = Now
        Else
            Target(, 3) = Now
        End If
        SendKeys "{TAB}"
    End If
    Application.EnableEvents = True
End Sub



I hope this helps! Let me know if you have any further questions.
 
Upvote 0
Thanks for your answer.
However, after ENTER. the cursor moves to the right when it should move down by default.
It would be possible?
Thanks in advance.
anvs
 
Upvote 0
Yes, it is possible to move the cursor down instead of to the right after pressing enter in column A. You can modify the code to simulate pressing the down arrow key instead of the tab key.

To do this, you can replace the line SendKeys "{TAB}" with SendKeys "{DOWN}". This will simulate pressing the down arrow key, which will release the cursor and move it down to the next cell.

The modified code would look like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim w
    If Target.Column > 1 Then Exit Sub
    Application.EnableEvents = False
    w = Target: Application.Undo
    If w <> Target Then
        Target = w
        If Target(, 2) = "" Then
            Target(, 2) = Now
        Else
            Target(, 3) = Now
        End If
        SendKeys "{DOWN}"
    End If
    Application.EnableEvents = True
End Sub

I hope this helps! Let me know if you have any further questions
 
Upvote 1
Solution
Pleasure... and glad to assist... Might I just ask that you do not mark your post #5 as the answer... please make #4... it will make it easier for other to get the solution.😎
 
Upvote 0
@anvs In future please mark the thread with the solution, rather than you post saying it works. Thanks
 
Upvote 0
Pleasure... and glad to assist... Might I just ask that you do not mark your post #5 as the answer... please make #4... it will make it easier for other to get the solution.😎
Done, I think.
Thanks
anvs
 
Upvote 0

Forum statistics

Threads
1,215,150
Messages
6,123,312
Members
449,094
Latest member
Chestertim

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