ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   strings (https://www.excelbanter.com/excel-programming/368732-strings.html)

RobcPettit[_2_]

strings
 
Hi, In range("a1") I have '20 Points - 5 Card Charlie' or '20 Points -
Black Jack'. The 'x Points -' can be any number. How do I ask in vba
does the sting contain '5 Card Charlie' or 'Black Jack'
Regards Robert


Dave Peterson

strings
 
one way:
=if(countif(a1,"*5 card charlie*")0,"Found it","nope")

or
=if(isnumber(search("5 card charlie",a1)),"yep","nope")

You could use Find (instead of Search) if you wanted case sensitive results.

RobcPettit wrote:

Hi, In range("a1") I have '20 Points - 5 Card Charlie' or '20 Points -
Black Jack'. The 'x Points -' can be any number. How do I ask in vba
does the sting contain '5 Card Charlie' or 'Black Jack'
Regards Robert


--

Dave Peterson

RobcPettit[_2_]

strings
 
Thankyou for your reply. This is great for in the worksheet, but i need
to do it in vba.
Regards Robert
Dave Peterson wrote:
one way:
=if(countif(a1,"*5 card charlie*")0,"Found it","nope")

or
=if(isnumber(search("5 card charlie",a1)),"yep","nope")

You could use Find (instead of Search) if you wanted case sensitive results.

RobcPettit wrote:

Hi, In range("a1") I have '20 Points - 5 Card Charlie' or '20 Points -
Black Jack'. The 'x Points -' can be any number. How do I ask in vba
does the sting contain '5 Card Charlie' or 'Black Jack'
Regards Robert


--

Dave Peterson



RobcPettit[_2_]

strings
 
Solved it. Used
If InStr(Range("c13"), "5 Card Charlie") Then
charlie = "5CC"
Else
charlie = ""
End If

Thankyou Regards Robert


Dave Peterson

strings
 
Oops. Sorry about missing the VBA stuff.

You may want to use something like:

If InStr(1, ActiveSheet.Range("c13").Value, _
"5 card charlie", vbTextCompare) 0 Then

if you don't care about case.

(and I like to qualify my ranges...)

RobcPettit wrote:

Solved it. Used
If InStr(Range("c13"), "5 Card Charlie") Then
charlie = "5CC"
Else
charlie = ""
End If

Thankyou Regards Robert


--

Dave Peterson


All times are GMT +1. The time now is 12:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com