VBA for message box targeting a cell and specific word (string) selection

dwarnimont

Board Regular
Joined
Jan 12, 2010
Messages
71
Asking for help to create VBA code for a message box.

Objective: A targeted cell, using a list dropdown with several options posts a message if a specific string is selected from the list

Part 1: If a list dropdown option is selected (change) containing a specific text string (or value?), a messagebox will popup with a specific message.
Part 2: the yes/no, if/else branch. I have the second part of the code , but I don’t know how to create the first part.

Sub SayHello()
Msg = "message to user "
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
MsgBox "Oh, never mind."
Else
MsgBox "I must be clairvoyant!"
End If
End Sub


Thanks,
David
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim msg As String
   
   msg = "message to user "

   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("[COLOR=#ff0000]F7[/COLOR]")) Is Nothing Then
      If LCase(Target.Value) = "hi" Then
         If MsgBox(msg, vbYesNo) = vbNo Then
            MsgBox "Oh, never mind."
         Else
            MsgBox "I must be clairvoyant!"
         End If
      End If
   End If
End Sub
This needs to go in a sheet module.
Right click the tab with your dropdown > select view code > paste the code into the window that opens.
Change the range in red to suit
 
Upvote 0
This isnt working by use within a list dropdown. it's odd. if you overwrite the list cell selection it does work. Did you try? Thoughts? Thanks for your help!!!!
 
Upvote 0
When you say a "dropdown" are you talking about a Data Validation dropdown, or something else?
 
Upvote 0
If found the cause of failure LCase. my list include Caps. why was this included? Can you simply remove it?
 
Upvote 0
As long as the string being checked in the code is all lower case (in my example "hi") then it will work regardless of whether the cell is hi, Hi, HI or even hI.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,693
Members
449,048
Latest member
81jamesacct

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