Messagebox in VBA in Excel

Asked

Viewed 157 times

0

Dear friends, good afternoon I am working on a dynamic table in excel and I would like when the store text 10 was typed, it displayed a warning that this store is unavailable, I know I need to call a messagebox but I have no idea what other structure I need to use, can help please?

  • I just want an example of a VBA code for when it is typed "store 10" in a cell is displayed a messagebox... it would be 'messagebox("store is unavailable")' but how do I put the conditional to the cell? that’s the doubt that’s haunting me

  • Why don’t you create a combobox with the possible stores? It would be much easier.

  • Any cell in a spreadsheet?

  • yes, any cell in the spreadsheet. @Reginaldorigo the system is old of a store, would have to reform it whole to implement otherwise

1 answer

0

Insert Event code

Use the event Worksheet_Change, where the data shall be placed within the worksheet in which the data is located. For example, in my case it was in Planilha1:

Planilha1

Code for a cell

The code is triggered every time the spreadsheet has some change and has a condition that if the value is equal to "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, because every time a cell is changed. This event will be triggered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.