VBA for Pop Up Message with Condition

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
348
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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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