VBA to create a pop up message, when text is entered in a cell

FrancisM

Board Regular
Joined
Apr 12, 2016
Messages
139
The following cell provides a pop up message when NO is entered in cell H5.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("H5") = "No" Then
MsgBox "If there is pink in a previously filled cell, after checking No." & vbCrLf & _
"There is Scheduling conflict." & vbCrLf & _
"Choose another time or reschedule the first veteran" & vbCrLf & _
"Remember! New career Link Visits require 1 hour.", vbCritical, "Vocational Services Database - " & ActiveSheet.Name
End If
End Sub

However when I try to expand it the these ranges H6:H10, H13:H17. I get a error message. Run time error 13. Type mismatch. I have even tried range H:H & received the same error. What am I doing wrong & how do I correct it.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Not sure if you have another purpose for using VBA but i just tested it using "Data Validation" and it works just fine for me. Just select the range you want and every time i type NO it prompts me with the message i wrote.

thanks
LouisT
 
Upvote 0
.
Try this :

Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myCell As Range


    For Each myCell In Range("H6:H10", "H13:H17") ': Range ("H13:H17")
            If myCell = "No" Then
                MsgBox "If there is pink in a previously filled cell, after checking No." & vbCrLf & _
                "There is Scheduling conflict." & vbCrLf & _
                "Choose another time or reschedule the first veteran" & vbCrLf & _
                "Remember! New career Link Visits require 1 hour.", vbCritical, "Vocational Services Database - " & ActiveSheet.Name
                Exit Sub
            End If
        
    Next myCell
End Sub
 
Upvote 0
Try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("H5:H10, H13:H17")) Is Nothing Then
        If LCase(Target.Value) = LCase("No") Then
            MsgBox "If there is pink in a previously filled cell, after checking No." & vbCrLf & _
            "There is Scheduling conflict." & vbCrLf & _
            "Choose another time or reschedule the first veteran" & vbCrLf & _
            "Remember! New career Link Visits require 1 hour.", vbCritical, "Vocational Services Database - " & ActiveSheet.Name
        End If
    End If
End Sub
 
Upvote 0
I'm sorry, I was posting at the same time that you did it.
 
Upvote 0
Thanks for the post. I forgot about the checking to see >1. I also see that I left out the )) on one of my attempts. The only question I have is regarding If LCase(Target.Value) = LCase("No") Then. What does that piece of code do? It s probably a dumb question, please humor me
 
Upvote 0
Thanks for the post. I forgot about the checking to see >1. I also see that I left out the )) on one of my attempts. The only question I have is regarding If LCase(Target.Value) = LCase("No") Then. What does that piece of code do? It s probably a dumb question, please humor me

You can capture "NO", "No", "no", "nO", LCase convert it to lowercase: "no". So always compare "no" with "no"
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top