VBA Code for Pop Up

Tennisguuy

Well-known Member
Joined
Oct 17, 2007
Messages
564
Office Version
  1. 2016
Platform
  1. Windows
I am trying to create a pop up window with VBA code. I am not good with VBA code but found some things on line but it's not working. I want to have a pop up window display a message once if the value in F7 equals a certain value and if possible have it only popup again if the value in F7 changes and meet another criteria.

This is the code I have but it not working.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F7:F7")) Is Nothing And _
If Range("F7").Value =1 Then MsgBox "RISK SCORE OF 1 IS 20% OR MORE LOWER THAN YOUR AVERAGE RISK"
If Range("F7").Value =2 Then MsgBox "RISK SCORE OF 1 IS 20% OR MORE LOWER THAN YOUR AVERAGE RISK"
If Range("F7").Value =3 Then MsgBox "RISK SCORE OF 1 IS 20% OR MORE LOWER THAN YOUR AVERAGE RISK"
If Range("F7").Value =4 Then MsgBox "RISK SCORE OF 1 IS 20% OR MORE LOWER THAN YOUR AVERAGE RISK"
If Range("F7").Value =5 Then MsgBox "A RISK SCORE OF 5 IS TYPICALLY 0% TO 5% LOWER THAN YOUR AVERAGE RISK IN YOUR DATA"
If Range("F7").Value =6 Then MsgBox "RISK SCORE OF 6 IS 0% TO 7.5% MORE HIGHER THAN YOUR AVERAGE RISK"
If Range("F7").Value =7 Then MsgBox "RISK SCORE OF 7 IS 7.5% TO 15% MORE HIGHER THAN YOUR AVERAGE RISK"
If Range("F7").Value =8 Then MsgBox "RISK SCORE OF 8 IS 15% TO 25% MORE HIGHER THAN YOUR AVERAGE RISK"
If Range("F7").Value =9 Then MsgBox "RISK SCORE OF 9 IS 20% TO 25% MORE HIGHER THAN YOUR AVERAGE RISK"
If Range("F7").Value =10 Then MsgBox "RISK SCORE OF 10 IS 25% TO 30% MORE HIGHER THAN YOUR AVERAGE RISK"
End If
End Sub
 
Oh forgot one other question, Joe if I wanted to add code for another cell on the sheet how do you add another module
If you mean that you want to add another "check" to the same worksheet, you cannot add another "Worksheet_Change" event procedure to the same worksheet.
Instead, you must add another block of code to the existing procedure.

So, let's say that you wanted to check both F7 and then Z7 (and do something else then). The structure could look something like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Block 1
If Not Intersect(Target, Range("[B][COLOR=#ff0000]F7:F7[/COLOR][/B]")) Is Nothing Then
    'code to run here
End If

'Block 2
If Not Intersect(Target, Range("[B][COLOR=#ff0000]Z7:Z7[/COLOR][/B]")) Is Nothing Then
    'code to run here
End If

End Sub
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
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