message box for text value (1 Viewer)

whhaatt

Registered User.
Local time
Today, 01:38
Joined
Aug 10, 2005
Messages
42
Is it possible to setup excel (VBA) to return a msgbox if certain text is entered into a cell - and if not then no msg is displayed?

ie if cell value is "test" then msg box appears with msg
if cell value is anything else then msg box does not appear


If possible can this be done on a range of cells - please remember that msg box is for text value and not numeric

Thankyou
 

chergh

blah
Local time
Today, 09:38
Joined
Jun 15, 2004
Messages
1,414
you want to use the sheetchange event of the workbook.

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


    'range defined here is C3 - J10
    
    If Target.Column >= 3 And _
       Target.Column <= 10 And _
       Target.Row >= 3 And _
       Target.Row <= 10 And _
       Target.Value = "test" Then
       
       MsgBox ("You win")
    
    End If
    
End Sub

This is case sensitive so use:

Code:
lcase(Target.Value)

If you don't care about case.
 

Users who are viewing this thread

Top Bottom