+ Reply to Thread
Results 1 to 8 of 8

Loop through a string and find the character/string need

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Loop through a string and find the character/string need

    Hello excel experts,

    May I know what's the formula to search for a particular string?

    i.e. I have QUOT20140711-9527-5212a priced on Monday. SOMETIMES I do have a space in between '-'.
    i.e. I have QUOT20140711-9527- 5212a priced on Monday. Notice the extra space after the '-' and before 5212a?

    My question is then, how do I get 5212a in this case?

    I know for sure that it'll be QUOT[YYYYMMDD]-(_)####(_)-(_)@@@@@@(_)priced on
    where (_) is a space depending on user input (some uses a space in between hyphens '-'
    @@@@@@ could be any "PO" number

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Loop through a string and find the character/string need

    Is it always the final 5 characters you are looking for?

    Edit: actually, and I don't know your application or how many users there are, but would it be feasible to apply Data Validation to allow only a certain number of characters (assuming a space-free string is always the same length), to discourage non-data-critical entries such as spaces in the first please? This would force data integrity and allow for simpler data management.
    Last edited by Speshul; 07-15-2014 at 10:30 AM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Re: Loop through a string and find the character/string need

    No...not necessary. that's why I put @@@@@ as it could be more or less than 5.

    What is known for sure is that it'll be after a hyphen (e.g. 9527-5212a priced), or hyphen and space (e.g. 9527- 5212a priced) and then @@@@@ and then a space follow with the word 'priced'

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Loop through a string and find the character/string need

    =SUBSTITUTE(A1," ","")

    Will remove the spaces from A1. So use this formula anywhere you use an "A1" in the formula you currently use to extract the hyphen separated values.

  5. #5
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Re: Loop through a string and find the character/string need

    I guess I need to include another statement.

    Currently I have the following formula in place that would give me ranking. However, because there's a space after a hyphen sometimes, it threw my ranking. Therefore, I'm now trying to find a way how to get the string and do a comparison. This way, doesn't matter how the user input is going to be on the string, it'll only compared the @@@@@.

    With the substitute, I can't seems to implement it in my current formula.

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Loop through a string and find the character/string need

    Try

    =COUNTIFS($A:$A, "=QUOT*",$A:$A, "<="&SUBSTITUTE(A8," ",""))

    I got 3 on each row when I posted the following in column A, with the previous formula I was getting 1, 2, 3. Is this what you need?
    QUOT20 140 711- 9527- 521 2a
    QUOT20140711-9527- 5212a
    QUOT20140711-9527-5212a
    Last edited by Speshul; 07-15-2014 at 10:58 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Re: Loop through a string and find the character/string need

    Interesting...I actually got a ranking on the "total"
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Loop through a string and find the character/string need

    Because "Total:" is equal to itself,

    ,$A:$A, "<="&SUBSTITUTE(A21," ",""))

    Unmerge the Total Row so it's only in column C, doesn't need to be A:C

+ 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] Find a character in a string that comes first but could be anywhere.
    By DumbTourist in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-25-2014, 01:39 AM
  2. [SOLVED] find the character position in a string of the last occurrence of a nominated character
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2014, 11:52 PM
  3. find a character in a string
    By chibouki in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-03-2012, 12:38 AM
  4. Replies: 2
    Last Post: 06-16-2010, 09:01 AM
  5. find a character in a string
    By captain bob in forum Excel General
    Replies: 1
    Last Post: 08-03-2006, 08:50 AM

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