MessageBox in VBA in Excel

0

Hi, I'm working on a PivotTable in Excel and I would like it when I typed the text store 10, it would display a warning that this store is unavailable, I know I need to call a messagebox however I have no idea what other structure need to use, can you please help?

    
asked by anonymous 23.08.2018 / 20:27

1 answer

0

Enter Event Code

Use the Worksheet_Change event, which must be placed inside the spreadsheet where the data is located. For example, in my case it was in Sheet1:

Codeforacell

Thecodeisfiredeverytimetheworksheethasanychangesandhasaconditionalifthevalueisequalto"Store 10".

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo CleanExit
    Application.EnableEvents = False

    If Target.Value = "Loja 10" Then
        Target.Value = ""
        MsgBox ("Não existe Loja 10!")
    End If

CleanExit:
    Application.EnableEvents = True
    On Error GoTo 0
End Sub
  

Note: The event can cause slowness, since every time a cell changes. This event will fire.

    
23.08.2018 / 20:44