|
Pop-Up Message Box When a Cell Reaches a Certain Value or Contains Certain Text
This macro will display a message box in excel when a cell reaches a certain value or contains certain text. This means that when cell A1 contains the value "hi" a message box will pop-up telling the user that cell A1 now contains the word "hi".
This macro can be changed to display a message box whenever a cell meets whatever criteria you want. You can change the criteria to display a message whenever certain text is entered into a cell by changing ,in this line of code, If rng = "hi" Then the "hi" to whatever you want. You can also change the display message to whatever you would like by changing the text inbetween the quotation marks in this code MsgBox "Cell " & _
rng.Address & " = hi". Also, if you want to change the cell to which the value must be entered for a message box to appear, change the A1 in this line of code to whatever you would like Set rng = Range("A1").
This macro is particularly useful in forms in excel. This way you can solicit input from a user and when he/she enters something, you can have a message box appear to remind them of something or to warn the user etc. This is pretty versatile code and is easily modified to check for many different types of values or characters and to then display the pop-up message box in excel.
Where to install the macro: Worksheet
Pop-Up Message Box When a Cell Reaches a Certain Value or Contains Certain Text
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range
Set rng = Range("A1")
If Not Intersect(Target, rng) Is Nothing Then
If rng = "hi" Then
MsgBox "Cell " & _
rng.Address & " = hi"
End If
End If
Set rng = Nothing
End Sub
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
Hello all,
Is there a way to setup Excel to automatically generate an e-mail message to at least one e-mail address, if a certain cell value has reached a given value ?
For instance, a message to be sent to e-mail address "name@e-mail.com", if cell B10, part of worksheet "Worksheet_1" has reached value 10.99.
Any idea would be more than welcome. Thank you.
Romulus.
Hi all,
I have created a popup message when a cell falls below a value. What I would like to do, is if that value is below 0, then I would like the text from another cell be put into my popup message at the beginning of the message. Example, if the cell value in P5
How can I disable Excel 2007 from displaying the cell information when hovering the mouse on it. This is only happening to one spreadsheet forward to me by somene.
Atached is a screenshot of the pop up.
Thank you all in advance.
Hi,
How would I go about finding the specific text "ACharge" in column A, and when it finds the text, insert rows until the text reaches row 20? The text always varies on a large number of spreadsheets and is always within the first 18 cells.
Any help would be much appreciated!
thanks
Hi Guys,
I'm preparing an excel document for my manager, and I have all the fields set out etc. My question is, would it be possible to make it so that when, whatever he is entering reaches the END of the row, it automatically carries over into the row below it? I don't want him to have to worry about resizing the rows to make the text fit in, so would like to make it so that when he reaches the end of the cell the text carries over into the row below it.
Thanks in advance.
Cheers.
Hello all, I have a test form which I've attached. What I'm trying to accomplish is open a hyperlink window when hitting a submit button and insert the hyperlink into the same field as something else just at the bottom of it.
So what you should do is when you click on the "Add Notes" button a userform will popup. When you check the box for add picture link and hit the submit button I'd like it to popup a hyperlink at the bottom of the text in cell. Attached is a picture of what it should look like.
Only thing I was able to figure out so far was:
VB:
Application.Dialogs(xlDialogInsertHyperlink).Show
If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines
If anyone has suggestions it would be greatly appreciated.
Thanks!
-Brandon
untitled.JPG
I've added a box that pops up when I click on a cell which visually reminds me how to input information into the cell ... my question, did this back 4 or 5 years ago and can't remember how to create again for a new cell (hope I'm clear on this) ... don't even remember what the pop up box is called, I know its not a comment box ... see RED box in attached image - Thanks in advance to your help
Hi Everyone,
I'm having some trouble with this code below. Would someone be able to give me some pointer.
I keep getting a compile error"user- defined type not defined"
Thank You as always for your support!!!
Mike,
Code:
Sub Box()
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Large Order?" ' Define message.
'MsgBoxStyle.DefaultButton2 Or _
'MsgBoxStyle.Critical Or
style = MsgBoxStyle.YesNo
title = "Order Area" ' Define title.
' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then ' User chose Yes.
' Perform some action.
Call AddHeader
Else
' Perform some other action.
Call AddHeader2
End If
End Sub
Hello.
I have a worksheet that populates specific cells(eg)v37 to v51 through v lookup
Code:
=IF(ISNA(VLOOKUP(ROW()-36,$AC$13:$AC$44,1,FALSE)),"",INDEX($L$13:$L$44,MATCH(ROW()-36,$AC$13:$AC$44,0)))
is there a way I can get a message box to pop up and warn users when the last cell is populated.In this case v51 thanks in advance for any help you can give me.
Hi,
I have a workbook that has 22 tabs and I would like to have a popup message box giving general instructions on how to use the workbook. (company workbook) I am not familiar with VB coding at all, so I'm wondering if someone could help me out?
Thanks in advance for your help.
|
|