Conditional Popup Message

daisydogflutist

New Member
Joined
Dec 3, 2007
Messages
6
Hi,
I want to display a warning message to users if a value in a certain cell meets certain criteria. Can someone help me with the code to do this?

More details:
The code will need to search Column A for certain strings. If it finds one of those strings on row x, and the value in Column F in row x is greater than 5.0%, a message should popup suggesting that the user should do something else.

Thanks!
~Brittany
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the Board!

How do you want this message to be triggered? Do the values in A and/or F get entered manually?

What's the criteria for A?

The following code assumes that data is being entered in A and tests if it's greater than 1 and F is greater than .05:

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#007F00">'   Code goes in the Worksheet specific module</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#007F00">'   Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> rng = Target.Parent.Range("A:A")<br>             <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Only look at that range</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Intersect(Target, rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Action if Condition(s) are met</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target > 1 And Target.Offset(, 5) > 0.05 <SPAN style="color:#00007F">Then</SPAN> MsgBox "Yo, do something else"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0
1- when is this msg should be triggered?
2- Is the search value hardcoded or should the code check for a value in a cell?
3- When the code does the comparison, will it check if the cell value is equal to the search value or only the part of the value in the cell is equal to search value?
 
Upvote 0
Pennysaver and iggydarsa, thanks for your replies. Unfortunately, I don't understand much of what was in your posts. :( I am very new to coding. I understand a lot of coding concepts, just not how the syntax works.

I think perhaps I should split this up into several sections so that you can better understand what I'm trying to do and I can better understand what you're telling me.

1. Let's assume that I have a list of strings somewhere on a different worksheet. In actuality, it is a list of chemical elements. Let's say it is on Sheet 3, all in Column A, and has one element in each cell. There are only 5 elements on this page, and they are Na, O, Cl, Zn, and Hg. On Sheet 1 in Column A, a user has entered a bunch of elements, several of which may be in the limited list I have in Sheet 3. What kind of statement should I use to test if any of the elements they list on Sheet 1 in Column A are contained in the list of 5 elements on Sheet 3?

2. For every element they list in Sheet 1, Column A, the user also lists the mass they have of that element in Column C, and it calculates the percentage of the total mass in Column F. Now, if the element they listed on Sheet 1 is contained in the list on Sheet 3, AND the percentage of that element is >5%, then I want to display the warning message. How do I check for these things and then display a warning message?

Iggydarsa, I think I understand your questions, and here are my answers:
1. I have a command button that the user is supposed to use to sort the data. I assumed that I could put this code into the macro code for that button so that when they click the button, it will check for these things (and perhaps display the message) as well as sort the data.
2. I think I answered that above. If not, rephrase the question.
3. The code will check if the cell value is equal to the search value. I think. :-\
 
Upvote 0
1. I have a command button that the user is supposed to use to sort the data.
From this statement I assume you already have a commandbutton that some type of macro already assigned to it... If so, add the following code to the end of the existing code, and lets see if it will do the job you want

Code:
Dim str1 As String: str1 = ""
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
    For j = 1 To Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
        If Range("A" & i).Value = Sheets("Sheet3").Range("A" & j).Value Then
            If Range("F" & i).Value > 0.05 Then
                str1 = str1 & Chr(13) & "Row: " & i & "   " & Range("A" & i).Value & " is >5%"
            End If
        End If
    Next j
Next i

If str1 <> "" Then
    MsgBox str1 & Chr(13) & Chr(13) & "Fix the list above"
End If
 
Upvote 0
Where can i see the command button? I dont understand. I want to show the sort warning as well. Im really new with it.
 
Upvote 0
Welcome to the Board!

You need to draw one, either from the Forms toolbar or the Control Toolbox, both under View-->Toolbars.

For the first, once you draw it you'll be prompted to assign a macro to it, so you'll have to take Iggy's code and put it into a module first (provided your criteria is the same, if not you'll need to post back and explain what you're trying to accomplish).

Hit ALT+F11 to open the VBE, then Insert-->Module and paste the code into the new window that opens on the right.

Note that you'll need start with: Sub Macro1() to the beginning of the and after you get done typing that End Sub will appear. Paste the code in between those two lines.

Hopefully that's a start,
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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