How to see if one string contains another string?

ExcelFilter: I don't see an easy one-function way to get the initial letters of a text string in Excel. Is there such a beast?

  • ExcelFilter: I don't see an easy one-function way to get the initial letters of a text string in Excel. Is there such a beast? [=Text(MI)] I need to do this for the first N words in the string. Let's say I have cells at A1 and B1 that look like this: [A Test Text String] [Another testing string, with more words] In this case, I'd like to get the values "ATTS" and "ATSW." All the cells I need to operate on will always hold only strings. [=INTITALS(A1,4)] is the ideal case, but as I said, it seems to not exist. TYVM.

  • Answer:

    =LEFT(A1,5)

mwhybark at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

whoops, ignore my answer.

skwm

Nope, there isn't such a beast. To do this, you'll have to write a ( Visual Basic | Microsoft ) script.

escher

It's possible to do in Excel, but the result is going to be one terribly nasty piece of code (Probably like 40 characters of typing per character you want to check). Basically, embedded if statements checking if each letter is a space, and if so, going back one letter and outputting that. I'm certain it's possible. But I don't have excel anymore to demonstrate it. Sorry.

shepd

I don't think there is any one function, but this does not require visual basic if the strings are of comparable length. I think it will require three steps. If "A Test Text String" is in A1, use row A to find all the spaces. Put "=FIND(" ", $A$1)" in B1 and "=FIND(" ",$A$1,B1+1)" in C1. From C1 you can just fill right to extend the process of locating spaces in the string as far as you need to. In row B, grab the characters that follow the spaces. A2=LEFT(A1,1) B2=MID($A$1,B1+1,1), and again fill right as far as you need to. Step 3 is to use =concatenate() to add up the bits in row B. You will have to fill right far enough to accomodate the string with the most spaces, and then clean up your results by trimming off any trailing spaces in the output.

shinnin

If it's always the same number of characters (4), you can use the following function in a single cell. Just repeat the pattern for more characters and replace all instances of "A4" with whatever cell you want to grab the caps from. (yeah it's messy, but it works :) =LEFT(A4,1) & MID(A4,SEARCH(" ",A4) + 1,1) & MID(A4,SEARCH(" ", A4, SEARCH(" ",A4)+1)+1,1) & MID(A4, SEARCH(" ", A4, SEARCH(" ", A4, SEARCH(" ", A4) + 1) + 1) + 1,1)

freshgroundpepper

Holy cow! I have also received non-member emails. One clearly requires posting: --- FROM: Paresh Ghaghda  to mwhybark Hello, I saw your question but am not a member. If you insert the following code into a VBA Module, you should find that the function INITIALS is now available as you described: Function INITIALS(str, n)     Dim x As Variant     x = Split(str, " ")     For i = 0 To n - 1         INITIALS = INITIALS & UCase(Left(x(i), 1))     Next i End Function HTH, Paresh --- Which would seem to be as perfect a thread closure as I have ever seen! Thanks to everyone, and Excel dev team members: please credit Paresh if an INITIAL text function crops up down the road. Damn, AskMe rules!

mwhybark

Also: Pepper, I thought I posted my deep appreciation earlier, but the phantom preview bug appears to have kilt it. To reiterate: I will try your solution forthwith. I look forward to implementing Paresh's as well.

mwhybark

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.