BeforeUpdate When User Enters Data Into Cell?

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I use this code to trigger code when the user changes the value in a particular cell (B6):

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Address = "$B$6" Then 
          ... do code ...
     End if
End Sub

Is this option doable? I have tried and am not getting any trigger when the user enters a value in cell K9. It's either because it's inappropriate, or I'm not following through properly.

Code:
Private Sub Worksheet_BeforeUpdate(ByVal Target As Range, ByVal Cancel As MSForms.ReturnBoolean)
    If Target.Address = "$K$9" Then
        Stop
        ... do code when user enters a value in K9 ...
    End If
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Private Sub Worksheet_BeforeUpdate
I am afraid you invented a new event, that does not (yet) exists in current Excel...

So you have to survive with Worksheet_Change; keep in mind that you can "Undo" the latest modification in Target, and this will make the situation as if it is a "BeforeChange"; for example:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewVal
'
     If Target.Address = "$K$9" Then
         Application.EnableEvents = False
            NewVal = Target.Value
            Application.Undo
    '          ... do code ...
        Application.EnableEvents = True
    End If
End Sub
After "Application.Undo" K9 will contain the original value, before the Change took effect; NewVal contains the changed value.
And don't forget that Worksheet_Change triggers only when an input is typed, not when a change occours via a formula

Bye
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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