MsgBox to Confirm Change

matrix1405

New Member
Joined
Jul 23, 2011
Messages
2
I have formulas in my speadsheet that I cannot protect due to the fact that the user will need to change the cell from time to time. I would like a msgbox to appear everytime they try to change the value of a cell, stating "Are you sure you want to change the value of this cell?", if user answers yes the value is changed, if no the value stays the same. I need this to apply for the range of cells $D$2:$AH$500. Please Help!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to the board. Give this a go - paste it into the module of the sheet in question...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim confirm As Variant

Application.EnableEvents = False

If Intersect(Target, Range("D2:AH500")) Is Nothing Then Exit Sub

confirm = MsgBox("Are you sure you want to change the value of the cell?", vbYesNo, "Formula overwritten!")

If confirm = vbNo Then Application.Undo

Application.EnableEvents = True

End Sub
 
Upvote 0
Try putting this in the sheet's code module.
Code:
Dim LastValue As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        If .Cells.Count = 1 And (Not (Application.Intersect(Target, Range("d2:ah500")) Is Nothing)) Then
            If LastValue <> .Value Then
                If MsgBox("Confirm Change", vbYesNo) = vbNo Then
                    On Error GoTo ErrorHalt
                    Application.EnableEvents = False
                    .Value = LastValue
                End If
            End If
        End If
    End With
ErrorHalt:
    Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    LastValue = Target.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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