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:
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.
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
– Rinarikato Mekitoji
Why don’t you create a combobox with the possible stores? It would be much easier.
– Reginaldo Rigo
Any cell in a spreadsheet?
– danieltakeshi
yes, any cell in the spreadsheet. @Reginaldorigo the system is old of a store, would have to reform it whole to implement otherwise
– Rinarikato Mekitoji