+ Reply to Thread
Results 1 to 24 of 24

Determine if certain characters are in a text string???

  1. #1
    Registered User
    Join Date
    07-06-2016
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    28

    Determine if certain characters are in a text string???

    Hi there,

    I'm writing a very long if statement formula. I need to add in a line that basically says if there is a "Q*" somewhere in the text, return a "-". It's not always in the same location in the text string so I'm having trouble figuring out a formula. I'd like to keep it as short and simple as possible since it's already a very long if statement and the size of my excel file is getting out of hand :S

    Thanks for the help!!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,623

    Re: Determine if certain characters are in a text string???

    Case sensitive:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Not case sensitive:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2404
    Posts
    13,407

    Re: Determine if certain characters are in a text string???

    With the understanding that you want to replace the "Q*" with a "-" in the string try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  4. #4
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    You can use this too :
    Case sensitive :
    Please Login or Register  to view this content.
    Not case sensitive :
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-06-2016
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    28

    Re: Determine if certain characters are in a text string???

    I actually need it to look for if there is an asterisk followed by Q, but I guess it's picking up to look for if it starts with a Q or has a Q at all... is there anyway to get around this?!

  6. #6
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    Can you provide an example? Then your requirements will be clear.

  7. #7
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    If you are trying to search whether it has Q*, then replace Q with Q* in the formula.

  8. #8
    Registered User
    Join Date
    07-06-2016
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    28

    Re: Determine if certain characters are in a text string???

    Sure. This is the current formula:

    =IFERROR(IF(AND(LEFT(AB2,1)=" ")*OR(LEFT(K2,4)="YPSD",LEFT(K2,4)="YPSA"),"-",IF(AND(LEFT(AB2,1)=" ")*OR(LEFT(P2,4)="YPSD",LEFT(P2,4)="YPSA"),"-",IF(AND(TODAY()>AF2)*OR(LEFT(K2,3)="YPS",LEFT(K2,3)="MTL"),"Shares",IF(AND(TODAY()>AF2)*OR(LEFT(P2,3)="YPS",LEFT(P2,3)="MTL"),"Cash",IF(AND(TODAY()>AF2)*OR(LEFT(K2,3)<>"YPS",LEFT(K2,3)<>"MTL"),"External PA",IF(AND(TODAY()>AF2)*OR(LEFT(P2,3)<>"YPS",LEFT(P2,3)<>"MTL"),"External PA",IF(AND(LEFT(D222,3)="MAT",LEFT(F222,3)<>"YPS*",LEFT(F222,3)=LEFT(P222,3)),"-","-"))))))),"-")

    What I need to add to it is if cell C2 contains a "Q*", "CAD", or "USD" in it I want it to return "External PA" (I had simplified for the sake of the post). I tested this formula =IF(ISNUMBER(SEARCH("*Q",C2)), "Yes", IF(ISNUMBER(SEARCH("USD",C2)),"Yes",IF(ISNUMBER(SEARCH("CAD",C2)),"Yes","No"))), but it was returning yes every time there was a capital Q in column C, as opposed to only returning a yes if there was a Q and an asterick.

  9. #9
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    Did you try that ?
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-06-2016
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    28

    Re: Determine if certain characters are in a text string???

    That doesn't work because I need this piece at the very front of the formula (because of the error value I would essentially have to put the value if false before the value if true, when I need the value if false to be second so I can continue the formula).

  11. #11
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    I didn't get you. What is the problem if you replace the "Your formula" with you own formula? Keep the other parts as same as it is now.

  12. #12
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    Here ISERROR is checking if the FIND function returning any error. If Find couldn't find any "Q*" here then it will execute your formula, else it will show "-".

  13. #13
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    Be sure that, I am using ISERROR, not IFERROR.

  14. #14
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Determine if certain characters are in a text string???

    Quote Originally Posted by cchap View Post
    What I need to add to it is if cell C2 contains a "Q*", "CAD", or "USD" in it I want it to return "External PA"...
    Like this...

    =IF(SUM(COUNTIF(C2,{"Q~*","CAD","USD"})),"External PA",...
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  15. #15
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    @ Tony Valko :
    Your formula will not work for him as he stated here that "Q*" will not be at same position.

    Quote Originally Posted by cchap View Post
    I need to add in a line that basically says if there is a "Q*" somewhere in the text, return a "-". It's not always in the same location in the text string so I'm having trouble figuring out a formula.

  16. #16
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Determine if certain characters are in a text string???

    Quote Originally Posted by sanram View Post
    @ Tony Valko :
    Your formula will not work for him as he stated here that "Q*" will not be at same position.
    But in post #8 they said this...

    What I need to add to it is if cell C2 contains a "Q*", "CAD", or "USD" in it I want it to return "External PA"...

  17. #17
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    Yes. Because he already stated that at Post#1.

    My formula should work for him. But may be he didn't get the difference between ISERROR and IFERROR. In his way he should try this :
    Please Login or Register  to view this content.
    May be he will understand then.

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Determine if certain characters are in a text string???

    Quote Originally Posted by sanram View Post
    =IF(ISERROR("Q*",A1),"No","Yes")
    That's not a valid formula.

  19. #19
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,924

    Re: Determine if certain characters are in a text string???

    Maybe this ...

    =IF(OR(ISNUMBER(SEARCH({"Q~*","USD","CAD"},C2))), "Yes", "No")

  20. #20
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    Sorry. It will be
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    07-06-2016
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    28

    Re: Determine if certain characters are in a text string???

    None of these seem to be working...or rather I can't seem to get that formula to work within my greater if statement. I've tried organizing it a few ways and it's returning "FALSE" or "Yes" every time.

  22. #22
    Registered User
    Join Date
    07-06-2016
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    28

    Re: Determine if certain characters are in a text string???

    I ended up adding a separate column to check the conditions:

    =IFERROR(IF(ISNUMBER(SEARCH("USD",C2)), "USD",IF(ISNUMBER(SEARCH("CAD",C2)),"CAD",IF(ISNUMBER(SEARCH("~*Q",C2)),"Q","-"))),"-")

    Then modified the second formula to:
    =IFERROR(IF(AS2="Q","-",IF(AND(LEFT(D2,3)="MAT",LEFT(F2,3)<>"YPS*",LEFT(F2,3)=LEFT(P2,3))*OR(AS2="CAD",AS2="USD"),"MM",IF(AND(LEFT(AB2,1)=" ")*OR(LEFT(K2,4)="YPSD",LEFT(K2,4)="YPSA"),"-",IF(AND(LEFT(AB2,1)=" ")*OR(LEFT(P2,4)="YPSD",LEFT(P2,4)="YPSA"),"-",IF(AND(TODAY()>AF2)*OR(LEFT(K2,3)="YPS",LEFT(K2,3)="MTL"),"Shares",IF(AND(TODAY()>AF2)*OR(LEFT(P2,3)="YPS",LEFT(P2,3)="MTL"),"Cash",IF(AND(TODAY()>AF2)*OR(LEFT(K2,3)<>"YPS",LEFT(K2,3)<>"MTL"),"External PA",IF(AND(TODAY()>AF2)*OR(LEFT(P2,3)<>"YPS",LEFT(P2,3)<>"MTL"),"External PA","-")))))))),"-")

    It's probably not the best approach since it adds another 1000+ lines of formula but I couldn't seem to get anything else to work.

  23. #23
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    can you upload a sample file?

  24. #24
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Determine if certain characters are in a text string???

    May be you can try this :
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Function to determine if a string contains multibyte characters or not
    By Monkihunta in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-24-2017, 09:53 AM
  2. Extract text between two characters in a string - varing text length
    By luv2birdie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-04-2014, 06:10 PM
  3. [SOLVED] Macro to create a new line within a text string if specific characters appear mid-string
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2014, 11:32 AM
  4. [SOLVED] How to determine if a cell has certian text for first three characters
    By proepert in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-10-2012, 10:20 PM
  5. Replies: 2
    Last Post: 01-16-2010, 01:57 PM
  6. Replies: 1
    Last Post: 04-18-2005, 05:06 PM
  7. Replies: 1
    Last Post: 04-17-2005, 08:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1