VBA checking to see if a string of text contains a certain syntax

mwhite0788

New Member
Joined
Aug 25, 2014
Messages
8
Hello,

What I am trying to accomplish is the following, One of the columns in my spreadsheet has Item Numbers in the form of ABC-123-100X50 for the Prefix ABC and DEF-123-50 for the prefix DEF, What i want to do is have a check that will see if the Prefix is ABC then the string must contain "-","-","X", otherwise it errors or warnings and if it has the Prefix DEF it must contain "-","-" or it errors. Any ideas on how I can accomplish this.

Thanks,

Mike
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You could try this formula in an adjacent column, or a variation of it according to your requirements

Code:
=IF(LEFT(A2,3)="ABC", IF(ISNUMBER(IFERROR(SEARCH("ABC-*-*X*",A2),"ABC Fail")),"ABC Pass","ABC Fail"), IF(LEFT(A2,3)="DEF",IF(ISNUMBER(IFERROR(SEARCH("DEF-*-*",A2),"DEF Fail")),"DEF Pass","DEF Fail"),""))

(Have assumed your original column of codes is in column A and starts at row 2...)

You may want to adjust the find_text arguments of the SEARCH formulas in case I've misinterpreted what it is you're trying to do
 
Upvote 0

Forum statistics

Threads
1,221,483
Messages
6,160,093
Members
451,617
Latest member
vincenzo1

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