VBA Help

TPRSCHM

New Member
Joined
Nov 16, 2017
Messages
10
I'm very new to using VBA so I'm sure this is a simple fix. I want a message box to display information when a defined item is picked from the validated drop down. I thought I had this all figured out when the message box started to haunt me. If I select the validated word all other drop down boxes will then give me the message no matter what is selected. Please see the VBA below and let me know what I have done wrong.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("B13") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub

ElseIf Range("B14") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub

ElseIf Range("B15") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub

ElseIf Range("B16") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub
ElseIf Range("B17") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub
ElseIf Range("B18") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub
ElseIf Range("B19") = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
Exit Sub
End If
End Sub

Thank You
Jim
 
The only way I could get Fluffs code to produce the error was to change multiple cells at a time. You could add a check to the code to see how many cells are changed and exit if it is more then one.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B13:B19")) Is Nothing Then
    If Target.Value = "LANE CLOSURE (MIN. OF 8 HOURS)" Then
        MsgBox "When LANE CLOSURE is utilized, reduced and prorate down one(1) laborer from CATEGORY A"
    End If
End If
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Scott T,

Thank you your code worked like a charm. I would also like to thank all that assisted on this problem. I have a lot to learn about VBA and I see that Mr Excel is a great place to get excellent advice

Jim
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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