VBA for Pop Up Message with Condition

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Hi There!

I need a macro to generate a pop-up message when a condition is met.

Thanks!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Thanks.

I am trying to say if any text like *LAB* is found in H:H and M:M, then generate a warning message reading "Enter Rate".

Thanks again.
 
Upvote 0
So assuming you want this script to run when *LAB* is entered into column M or Column H

So if LAB dog is entered or LAB Technician is entered into Column M or Column H a message box will pop up

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  1/15/2019  10:28:47 PM  EST
If Target.Column = 8 Or Target.Column = 13 Then
If InStr(Target.Value, "LAB") Then MsgBox "Enter Rate"
End If
End Sub
 
Upvote 0
Perfect.
Thank you.

How can I define ranges instead of Target.Column = 8 Or ....

Thank you
 
Upvote 0
Try this using named Range "Cake"

Modify as needed
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  1/15/2019  11:16:47 PM  EST
If Not Intersect(Target, Range("Cake")) Is Nothing Then
If InStr(Target.Value, "LAB") Then MsgBox "Enter Rate"
End If
End Sub
 
Upvote 0
Thanks.

Why does it give me the Run-time error 13 when I select any of those columns to past or clear data?
It does not give me that error when I update cell by cell though.
 
Upvote 0
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  1/15/2019  11:46:47 PM  EST
If Not Intersect(Target, Range("Cake")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If InStr(Target.Value, "LAB") Then MsgBox "Enter Rate"
End If
End Sub
 
Upvote 0
Code:
Private Sub xWorksheet_Change(ByVal Target As Range)
Dim rng As Range, cel As Range
Set rng = Intersect(Target, [H:H,M:M])
If Not rng Is Nothing Then
    For Each cel In rng
        If InStr(cel, "LAB") Then
            MsgBox "Enter Rate"
            Exit For
        End If
Next
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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