Change event

pam53154

Board Regular
Joined
Mar 3, 2009
Messages
107
I am new to VB programming for change events and have been trying to stumble through... but would appreciate some help. I am trying to write code which says if a user attempts to change cell A1, display a message box. Right now I have this and it is not working. Any thoughts? Thanks!!

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address = "$A$1" Then
If .Value <> "desired value" Then
MsgBox "Please don't change this cell"
.Select
End If
End If
End With
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try:
Rich (BB code):
Option Explicit
    
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Application.Intersect(Target, Range("A1")) Is Nothing Then
    
        If Not Range("A1").Value = "desired value" And Not Range("A1").Value = vbNullString Then
            Range("A1").ClearContents
            MsgBox "Please don't change this cell", 0, ""
            Range("A1").Select
        End If
    End If
End Sub
 
Upvote 0
I think I might be doing something wrong? I copied the code into VB, changed "desired value" to "10", then input several different values in cell A1 and nothing happened. I pulled other sample codes and none are working, either... so am I missing something?
 
Upvote 0
Hi Pam,

If you left the quote marks around the 10, ditch them.

Mark
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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