Adding multiple Msgbox to worksheet

TODDLL

New Member
Joined
Apr 7, 2018
Messages
24
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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,280
Office Version
  1. 365
Platform
  1. Windows
Which 3 columns do you want the message boxes for?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,280
Office Version
  1. 365
Platform
  1. Windows
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
 

TODDLL

New Member
Joined
Apr 7, 2018
Messages
24
Office Version
  1. 365
  2. 2010
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,280
Office Version
  1. 365
Platform
  1. Windows
Oops, bit of a typo on my part!:eek:
 

Watch MrExcel Video

Forum statistics

Threads
1,129,480
Messages
5,636,582
Members
416,927
Latest member
BNM8V6

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
Top