VBA code to have a message box appear if when a option is selected from a drop down list

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a cell with a drop down list in it and I want a message box to appear when a certain option is selected from the drop down list. I am pretty sure you can do it with vba but I don't know the code to do so. Can someone help me please?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You talking about a Data Validation list Dave ??

Code:
Sub MM1()
If cell(1, 1).Value = "YOUR CRITERIA" Then
MsgBox "you picked a name"
End If
End Sub
 
Upvote 0
Ok, then the code I supplied will do the trick !
 
Upvote 0
How do you want it activated ??
Is it going to part of a bigger code ??
You can call it from another macro, you can have it in a worksheet_change event, you can run it from a button !!

If you call it or run it from a button, put it in a regular module...otherwise in the worksheet.
 
Upvote 0
I am not sure how it will be activated. My supervisor wants the spreadsheet to be less cluttered and he suggested moving the text about changing the activity cost to a message box upon selecting activities, however, I am open to suggestions if you can think of a better way to do it.
 
Upvote 0
MAte....it would help if you provided all the info ??

Which sheet ?? and where on that sheet are we talking about ?
Remember though, it's probably more work to have a MsgBox pop up and then have to cancel or close it !!
you supervisor isn't named Peter is it .....??? I had one exactly the same....he didn't have a clue about VBA, except it must be simple to write !!!
 
Upvote 0
Sorry I didn't provide all the info and no, my supervisor's name isn't peter. Lol, these supervisors.


  • I will be on NPSS_quote_sheet.
  • The first row of data in the table in this sheet will be in row 11 and the drop down list is in column B.
    • This might have activities selected from the drop down list or it may not.
  • The activity column that will have the value entered in it from the message box that appears upon selecting it is in column N.


Which sheet ?? and where on that sheet are we talking about ?
Remember though, it's probably more work to have a MsgBox pop up and then have to cancel or close it !!
you supervisor isn't named Peter is it .....??? I had one exactly the same....he didn't have a clue about VBA, except it must be simple to write !!!

Not sure if you need this bit or not. It is the code that inputs the value upon the selection of activities.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
        Dim ans As String
        If Not Intersect(Target, Range("A:A,B:B")) Is Nothing Then
        Application.EnableEvents = False
        Select Case Target.Column
            Case Is = 1
                If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
                If Target.Value < Date Then
                    If MsgBox("This input is older than today !....Are you sure that is what you want ???", vbYesNo) = vbNo Then
                        Target.Value = ""
                    End If
                End If
            Case Is = 2
                If Target = "*Activities" Then
                    Do
                        ans = InputBox("Please enter the Activities cost.")
                        If ans <> "" Then
                            Cells(Target.Row, "N") = ans
                            Exit Do
                        Else
                            MsgBox ("You must enter a Activities cost.")
                        End If
                    Loop
                End If
        End Select
        End If
    Application.EnableEvents = True
End Sub

Thanks Michael,
Dave
 
Upvote 0
OK, found the cell....which option from that list do you want to trigger the code ??
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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