Adding multiple Msgbox to worksheet

TODDLL

New Member
Joined
Apr 7, 2018
Messages
27
Office Version
  1. 365
  2. 2010
I have 3 columns in a worksheet that will have either a Y or N entered into the cell. If Y is entered into the cell, I would like a msgbox to appear with instructions. Each of the 3 columns will have a different msg for Y. I cannot figure out how to add separate msg in the vba code for each of the columns. I can make it work for a single column but not sure how to write the vba for multiple. I tried the elseif statements but cannot make it work. Thanks for any help you can provide. Todd
Msgbox vba.png
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Which 3 columns do you want the message boxes for?
 
Upvote 0
Try something like this.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strMsg As String

    If Intersect(Target, Range("G9:G100")) Is Nothing Then Exit Sub

    If Target.Value = "Y" Then
        Select Case Target.Column
            Case 7
                strMsg = "You entered Y in column G."
            Case 8
                strMsg = "You entered Y in column H."
            Case 9
                strMsg = "You entered Y in column I."
        End Select
        MsgBox strMsg
    End If
    
End Sub
 
Upvote 0
Hi Norie,
I had a small problem with the code as it would only display the msg for column G, but I quickly figured it out by changing the Intersect range to ("G:I"). It now works perfectly. Thank you so much! I am thoroughly impressed by the great help I always receive on this site, and I rarely need to wait long to get an answer. I sincerely appreciate your help. Todd
 
Upvote 0
Oops, bit of a typo on my part!:eek:
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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