HELP: VBA that prompt message before close when certain cell is less than 100

  • Hi, i am new to marco. i need to some help that can make the file prompt up message (when saving the file), lets say cell E10 the total is less than 100.

    I tried many online sample but it does not prompt.


    i tried following sample online but nothing prompt


    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("E10").Value > 100 Then
    MsgBox "Try again total is not 100"
    End If
    End Sub

    Thank you in advance!!

    Edited once, last by royUK: Add Cod tags ().

  • Please read the Forum Rules to learn how to get the best results from the Forum. I have added code tags for you.


    You need to use the Before Save event. This event is a workbook event and should be placed in the WorkBook Module, read Where to paste code from the Forum if you are not sure what I mean. You also need to use the sheet name


    Code
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If sheet1.Range("E10").Value > 100 Then
    MsgBox "Try again total is not 100 in E10"
    Cancel = True
    End If
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!