Have to click on cell again for it to update

mystiedx

New Member
Joined
Jun 27, 2021
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
Hello to all.

I have the following code:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'when not to do anything

    If Target.Column <> 4 And Target.Column <> 5 And Target.Column <> 6 Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    If Not IsNumeric(Target.Value) Then
        MsgBox "Please, enter numbers only."
        Target.Select
        Exit Sub
    End If
   
    Dim fndRng As Range

    With ActiveSheet.Range("H:H")  ' <~~ the sheet with the list
    Set fndRng = .Find(What:=Target.Value, _
                       After:=.Cells(.Cells.Count), _
                       LookIn:=xlValues, _
                       LookAt:=xlWhole, _
                       SearchOrder:=xlByRows, _
                       SearchDirection:=xlNext, _
                       MatchCase:=False)
    If Not fndRng Is Nothing Then
        Application.EnableEvents = False
        Target.Value = fndRng.Offset(0, 1).Value
        Application.EnableEvents = True
    Else
        Target.Select
    End If
End With
End Sub

Form Teacher Remarks 1.xlsm
ABCDEFGHI
711trying
822Is self-confident and has excellent manners.
93tryingtrying3Sets an example of excellence in behaviour and cooperation.
1044Is a self-motivated student.
115Is a pleasant, respectful, and well-behaved student.Has shown noticeable improvement in her behaviour. Must keep it up.5Is a pleasant, respectful, and well-behaved student.
1266Is a nice and attentive student.
1371trying7Should be more responsible and disciplined in her behaviour.
1488Has shown noticeable improvement in her behaviour. Must keep it up.
159nopehello are you sure9Improvement of attitude towards work required.
1610tryingtrying10Is too often absent.
1711tryingtrying11Is too often late.
1812Is a pleasant, respectful, and well-behaved student.Sets an example of excellence in behaviour and cooperation.12try
191313nope
201414hello are you sure
211515
2216
7 GRATITUDE


When I press a number (example 1), it should display "trying" in the cell. However, this doesn't happen instantly. I must click the cell again for "trying" to appear. What I want is any of the test appears immediately when I press corresponding number.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I am not entirely clear on what you are trying to achieve but I suspect a lot of you issue centres around using
• Worksheet_SelectionChange
I suspect that you really want
• Worksheet_Change

Do you want to give that a try ?
 
Upvote 0
Solution
I am not entirely clear on what you are trying to achieve but I suspect a lot of you issue centres around using
• Worksheet_SelectionChange
I suspect that you really want
• Worksheet_Change

Do you want to give that a try ?

Works perfect.

I guess I'm still not clear about when to use SelectionChange v/s Change.

Anyway, thanks a lot Alex. ?
 
Upvote 0
No problem, glad I could help.
FYI
SelectionChange is when you move around the worksheet (eg from cell to cell). It would probably be unusual to need that.

When you enter something into a cell or copy/paste etc, that triggers the Change event.
This is the most commonly used worksheet event.
 
Upvote 0
No problem, glad I could help.
FYI
SelectionChange is when you move around the worksheet (eg from cell to cell). It would probably be unusual to need that.

When you enter something into a cell or copy/paste etc, that triggers the Change event.
This is the most commonly used worksheet event.

Ah ok.. Now I get it. I always thought that SelectionChange was used when the value in a cell changes.

Thanks again Alex.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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