Msg Box to appear if If Cell changes to certain value (cell contains formula)

Lisa05

New Member
Joined
Nov 25, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have couple of Cells Range A1:A12 that calculate percentage. I would like to set up a rule that if percentage in those cells is between 3% and 5% Msg box appears. I am trying following code:

Private Sub Worksheet_Calculate()
If Range("A1:A12").Value > 3% And Range("A1:A12").Value <= 5% Then
MsgBox "Message"
Else
Exit Sub
End Sub

Looks that the system does not accept above and it doesn't work
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You either need to loop through each cell in the range and check each one, or use a COUNTIFS formula on the range, like this:
VBA Code:
Private Sub Worksheet_Calculate()

    Dim rng As Range
    Dim crit1 As String
    Dim crit2 As String
  
'   Set range and criteria
    Set rng = Range("A1:A12")
    crit1 = "> 3%"
    crit2 = "<= 5%"
      
    If Application.WorksheetFunction.CountIfs(rng, crit1, rng, crit2) > 0 Then
        MsgBox "Message"
    End If

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,148
Messages
6,123,300
Members
449,095
Latest member
Chestertim

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