VBA Code for Pop-Up Window With Specific Word

Justinian

Well-known Member
Joined
Aug 9, 2009
Messages
1,557
Office Version
  1. 365
Platform
  1. Windows
I have a worksheet where I want a message box to appear when the letter "A" appears in the range I37:I69. I used to following code to accomplish this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Range("I37:I69").Find(what:="AA", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True) Is Nothing Then
MsgBox "Exact dimensions needed for ceramic pipe due to required shop fabrication. This can affect both pipe costs and leadtime."
End If
End Sub

The problem is that the message box appear when ANY cell is changed, not just when the letter "A" appears in I37:I69.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Sorry, I meant when "AA" appears in the range I37:I6. IF AA is the result of a formula, the message box does not appear; if you manually type in AA, then the message box appears and I cannot figure out why that isd.
 
Upvote 0
This event is used when you modify the cell.
Private Sub Worksheet_Change
In your case you are not modifying the cell, since the formula remains the same, the change is the result of the formula.

You can use the calculate event:

Code:
Private Sub Worksheet_Calculate()
    Set b = Range("I37:I69").Find(what:="AA", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
    If Not b Is Nothing Then
        MsgBox "Exact dimensions needed for ceramic pipe due to required shop fabrication. This can affect both pipe costs and leadtime."
    End If
End Sub



Or you can use the change event, but monitoring the cells involved in the formula of range I37:I69
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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