Adding extra Or value to this VBA code

MeaclH

Board Regular
Joined
Apr 2, 2014
Messages
93
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there,

I have this wonderful code running but would like to add a couple more values to consider when a value is changed.
Could you suggest a string of code to allow for multiple values to be considered.

Cheers,

Hayden
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Resp As String
Dim prevValue
prevValue = pVal

On Error GoTo ExitNow
Application.EnableEvents = False
If Target.CountLarge = 1 And Not Intersect(Target, Range("G11:T178")) Is Nothing Then '<--- Change Target Range Here
    If swapval = False Then
'---EDO/EDO-U
        If prevValue = "EDO" Or prevValue = "EDO-U" Then
            If InStr(Target.Value, "0" [B][COLOR=rgb(235, 107, 86)]MORE VALUES HERE)[/COLOR][/B] Then
                With Target
                    ActiveSheet.Unprotect
                    .Interior.Color = RGB(120, 210, 91)
                    .Font.Color = RGB(255, 0, 0)
                    'Input Box below. change text and title as needed:
                    Resp = Application.InputBox("You are allocating an open shift to a DAO on an EDO.         Please include details of when this shift was added and notify the DAO at the earliest opportunity.", _
                    Title:="Open shift added on an EDO")
                    ActiveSheet.Protect DrawingObjects:=False
                End With
            End If
        Else
 
This compiles if I add a couple of undeclared variables, but of course I can't test it. If I didn't say it before, try provided code on a copy of your workbook(s). If this isn't what you're after then I guess I'm not understanding the request. What's odd is that your code already seems to have made use of the suggestion down here:
VBA Code:
Select Case .Value
            Case "SDO", "STFN", "CDO", "CTFN", "SPDO" '<- Add more trigger values here if required
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Resp As String
Dim prevValue

prevValue = pVal
On Error GoTo ExitNow
Application.EnableEvents = False
If Target.CountLarge = 1 And Not Intersect(Target, Range("G11:T178")) Is Nothing Then '<--- Change Target Range Here
    If swapval = False Then
Thanks for your patience mate really appreicate it.
I managed to get your code going perfectly.
Legend!
Cheers,
Hayden
 
Last edited by a moderator:
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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