How can i change this line of code

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,266
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
HI All,</SPAN>
I have this code below.</SPAN>
If Status <> "Yellow Task" And Status <> "Pink Task" And Status <> "Green Task" And Status <> "Purple Task" And Status <> "Other" Then</SPAN>
Do Stuff….</SPAN>
Now I have this status list already defined (Code) in a worksheet</SPAN>
i.e - Defined - Names - Code</SPAN>
Yellow Task</SPAN>
PinkTask</SPAN>
Green Task</SPAN>
Purple Task</SPAN>
Other</SPAN>
Now how can I amend the code to say if status is <> one the items in the defined name (Code) then</SPAN>
do stuff</SPAN>
This way I can just update my code list rather than updating the code if I had more criterias</SPAN>
Thank You</SPAN>

<TBODY>
</TBODY><COLGROUP><COL></COLGROUP>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
HI All,</SPAN>
I have this code below.</SPAN>
If Status <> "Yellow Task" And Status <> "Pink Task" And Status <> "Green Task" And Status <> "Purple Task" And Status <> "Other" Then</SPAN>
Do Stuff….</SPAN>
Now I have this status list already defined (Code) in a worksheet</SPAN>
i.e - Defined - Names - Code</SPAN>
Yellow Task</SPAN>
PinkTask</SPAN>
Green Task</SPAN>
Purple Task</SPAN>
Other</SPAN>
Now how can I amend the code to say if status is <> one the items in the defined name (Code) then</SPAN>
do stuff</SPAN>
This way I can just update my code list rather than updating the code if I had more criterias</SPAN>
Thank You</SPAN>

<TBODY>
</TBODY>


Hi All,

Please advise if i am posting incorrectly. Is there a new procedure we need to follow when posting in this new layout?

Apologies if i am doing it incorrectly
 
Upvote 0
You could use Match.

Something like this perhaps.
Code:
Dim varCheck As Variant

varCheck = Application.Match(Status, Range("Code"), 0)
If IsError(varCheck) Then
    ' do things
 
Upvote 0
Lesceline

Nothing wrong with the post, though you could have put the code in tags.

Mind you it is only one line.
 
Upvote 0

Forum statistics

Threads
1,203,066
Messages
6,053,330
Members
444,654
Latest member
Rich Cohen

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