Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

I need a code either as vba or validation which will pop up a message after values in a…

  1. User

    I need a code either as vba or validation which will pop up a message after values in a sheet are changed. The pop up will ask if I want to allow the change I made to the cell value and if I select yes it will keep the change. If I however select No the cell will revert to its former value. I do not want the code to continuously loop.

  2. Assistant

    Here's a VBA code that will give you a message box when you change a value in a cell, and if you choose "No," it will undo the change:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim confirmation As Integer
    
    On Error Resume Next
    Application.EnableEvents = False
    
    confirmation = MsgBox("Do you want to save this change?", vbYesNo)
    
    If confirmation = vbNo Then
        Application.Undo
    End If
    
    Application.EnableEvents = True
    
    End Sub
    

    Just paste this code into the sheet module where you want this functionality to apply. This code will not continuously loop and will only give you the message box when a value in a cell is changed.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.