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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,216,021
Messages
6,128,319
Members
449,440
Latest member
Gillian McGovern

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