search a string in an excel cell

sanjog

New Member
Joined
Jan 11, 2013
Messages
26
within a single cell I have following character values separated by ,

VN,VI,VE,JP,TH,TW,HK,HM,HN,BR,PH,UM,NI,AR,BO,NZ,SG,KR,KH,ID,UY,SV,AW,US,PY,CR,MY,MF,CX,NF,PR,MO,CA,CC,GT,PA,EC,MX,AU,PE,AS,CN,CO

<tbody>
</tbody>

I have a lots of such entries that vary along the row for the same column no

I want to write a script to check 3 conditions and return the result accordingly

1. If the string contains "US" return 1
2. If the string contains "UK" return 2
3. If the string contains "US" and "UK" return 3
4. If the string contains "US" and "UK" and "FR" return 4

any formula or a VB script to do this effectively for variable rows and fixed column ?

Sanjog
 
Doesn't CountIf(A1,"*UK*") return just 0 (if "UK" is not found in A1) or 1 (if "UK" is found in A1, no matter how many times)?
@PGC,

Gulp! You are right... I forgot... I am counting a single cell, not a range. Thanks for noting that for me.


@sanjog,

As PGC noted, I included more than was necessary in my formulas. Here they are revised in accordance with PGC's comment...

Returning 0 for blank cells...

=COUNTIF(A1,"*US*")+2*COUNTIF(A1,"*UK*")+(COUNTIF(A1,"*US*")+2*COUNTIF(A1,"*UK*")=3)*COUNTIF(A1,"*FR*")

Returning the empty string ("") for blank cells...

=IF(A1="","",COUNTIF(A1,"*US*")+2*COUNTIF(A1,"*UK*")+(COUNTIF(A1,"*US*")+2*COUNTIF(A1,"*UK*")=3)*COUNTIF(A1,"*FR*"))
 
Last edited:
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,215,821
Messages
6,127,053
Members
449,356
Latest member
tstapleton67

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