Message Box Notification when cells in Column have a specific value

mporres77

New Member
Joined
May 7, 2018
Messages
5
I was wondering if anyone can help me with my message box notification.

What I want the macro to do is to check the values in column H and if it has a value that is <= 60, then to have a message box pop up with a specific message.

Then I want it to do the same thing for <= 30 with a different message if it finds that value.

The one I have now is working, however it gives me a message box for every single cell it finds with that value. Right now the sheet has 4 cells that have a zero value so I get 4 message boxes.

How can I correct the code to just give me 1 message box notification regardless of how many cells have that value?

Here is the code I have so far:
Private Sub Worksheet_Activate()
For Each cell In Range("H:H")
If cell.Value <= 60 And cell.Value <> "" Then
Range("H:H").Select

MsgBox "60 Days Until Renewal"

End If
Next
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Well, to get one message you'd want to move the msgbox line out of the "For" loop.

Typically, Id initialize a Boolean variable to False and then toggle it if you find a cell.

Like this:

Code:
Private Sub Worksheet_Activate()

Dim foundCell As Boolean: foundCell = False

For Each cell In Range("H:H")
     If cell.Value <= 60 And cell.Value <> "" Then

          Range("H:H").Select
          foundCell = True

     End If
Next

if foundCell = True Then
     MsgBox "60 Days Until Renewal"
End If

End Sub

This will solve the "multiple messages" issue, but I definitely still see some weird stuff going on elsewhere.

For instance.... Why are you selecting Range("H:H") in every iteration of the loop?

What if there are only 20 days left... Do you still want to display "60 Days..."

Maybe something like this would fix that:

Code:
MsgBox("Less than 60 Days Until Renewal")
 
Last edited:
Upvote 0
That worked perfectly. Thank you for your help.

I do not understand your question about Range("H:H"). The reason I need that only that column is because it is calculating how many days are left before we need to renew contracts that expire after 180 days. I originally wanted it to notify me when I activate the sheet that there are contracts that are either 60 days or less and or 30 days or less.

The way you have it here works better.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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