Closed Thread
Results 1 to 16 of 16

Find the index of substring in whole string in one cell

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Find the index of substring in whole string in one cell

    Hi Guys,

    i have joined string like here:

    "Vn_Input_HANA_Deployment_Description;Vn_Input_NetWeaver_Deployment_Description;Vn_Input_Oracle_Deployment_Description;Vn_Input_SBD_Deployment_Description;Vn_Input_Servers_Deployment_Description;Vn_Input_SharedStorage_Deployment_Description;Vn_Input_WebDispatcher_Deployment_Description"

    or here : "Vn_Input;Vn_Input;Vn_Input;Vn_Input;Vn_Input;Vn_Input"

    and now i have to lookup and find indexes for all matches in source table.

    So if i am looking for Vn_Input_HANA_Deployment_Description i would like to get "1" because it is the first substring in whole string.

    in second example where lookup value is: "Vn_Input" i would like to get 1;2;3;4;5;6 because i have everywhere matches.

    IT is possible with formula ? OR maybe VBA would better (if Yes admin please move to proper forum topics).

    I am attaching example workook to address.

    And in my source table i have also TableName to retrive.

    So generally steps i would take:
    1) find the row of source table where lookupvalue exists (we will not have duplicates here),
    i tried with :
    Please Login or Register  to view this content.
    but it is not working
    2) within found row check which position in string lookup value has and return index.
    3) if more than one matches return array as result.

    Thank you for help,
    Jacek

    EDIT: Link to VBA solution topic:
    https://www.excelforum.com/excel-pro...ml#post5584286
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by jaryszek; 10-20-2021 at 12:27 AM.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Find the index of substring in whole string in one cell

    You might want to add in the expected results?
    Rory

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    You mean Rory you want to see expected result ?
    Or what is the question?

    Best,
    Jacek

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Find the index of substring in whole string in one cell

    Yes I think it would help to show what results you expect and where.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Find the index of substring in whole string in one cell

    Assuming I understand what is needed, here's how I see this happening. I'm not sure which programming language I would choose, so I will also include options:

    1) Start with a semi-colon delimited text string.
    2) Split the text string into an array of elements.
    2a) In Excel, Text to columns. (helper cells)
    2b) In Google Sheets, Text to columns or split() function. (helper cells)
    2c) In VBA, split() function
    3) Search each element of the resulting array for the desired text substring.
    3ab) In Excel or Google Sheets: FIND() function (helper cells).
    3c) In VBA: Instr() function (inside of a loop) (store as array of integers)
    4) join the resulting array of integers into a semicolon delimited text string.
    4a) In Excel: TEXTJOIN() function (assuming you have access to it).
    4b) In Google Sheets: TEXTJOIN() function (since they don't hide anything behind subscription walls).
    4c) In VBA: Join() function.

    I would not be surprised if Power Query/Get and Transform has a similar set of commands, so that you could use Power Query's programming language to do this, too.

    At this point, it seems mostly a question of which programming language you prefer, which is probably as much as anything about how you want to interact with the spreadsheet.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Find the index of substring in whole string in one cell

    Maybe try this with Ctrl+Shift+Enter

    =MID(SUBSTITUTE(TEXT(MID(NPV(9;IFERROR(IF(FILTERXML("<x><m>"&SUBSTITUTE(INDEX(Source!$E$2:$E$6;MATCH(1;FREQUENCY(0;1/(1+LEN(SUBSTITUTE(Source!$E$2:$E$6&";";C4&";";C4&11))-LEN(Source!$E$2:$E$6)));));";";"</m><m>")&"</m></x>";"//m")=C4;ROW(A$1:A$9));""));3;9);REPT("\;0";6));";0";);2;99)
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    Thank you Guys,

    Rory,please find in attachment expected result.

    Screenshot_238.png

    BoRy,

    o wow what the monster formula! Thank you, i have to analyse.

    Mr Shorty, thanks for tips.

    Best,
    Jacek
    Attached Files Attached Files
    Last edited by jaryszek; 10-19-2021 at 12:14 AM.

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    Bo_Ry,

    awesome formula. thank you!

    Questions: If they are volatiles?
    or not? If yes wouldnt be better to use only VBA?

    Formula is very nice and very fast... but what i am afraif for 500 hundred rows it will decrese overall workbook perfomance.

    Best,
    Jacek

  9. #9
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Find the index of substring in whole string in one cell

    I rarely use volatile function.
    No, the formula is non-volatile.

    If you have Textjoin then

    =TEXTJOIN(";";;IFERROR(IF(FILTERXML("<x><m>"&SUBSTITUTE(LOOKUP(0;-FIND(C4&";";Source!$E$2:$E$6&";");Source!$E$2:$E$6);";";"</m><m>")&"</m></x>";"//m")=C4;ROW(A$1:A$9);"");""))
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    Thank you Bo_Ry,

    Oh i see ROW() is not volatile and ROWS() are volatile right?

    i need to understand this

    Please Login or Register  to view this content.
    how this filterXML is working?

    i do not catching it.
    and what doest -FIND ?

    Best,
    Jacek

  11. #11
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    What i have notice the first lookup string has more than 255 characters and always this function is throwing #VALUE:

    Please Login or Register  to view this content.
    so getting :

    Please Login or Register  to view this content.
    Why ?

    And why this FILTERXML is working? I tried with MAtch ("*" & C4 & "*") but it is retirning $VALUE...
    With FILTER i have the same...

    Please advise,
    Jacek

  12. #12
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    Can anybody explain how this is working in simple and plain english ?

    Will be grateful.

    Best,
    Jacek

  13. #13
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    Anyone can explain ?

    BO_RY disappeared...

    Best,
    Jacek

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Find the index of substring in whole string in one cell

    You have a solution to this in the VBA forum. Why do you have two threads running on the same issue? If the objective is DIFFERENT, then the thread titles should also be different and reflect the difference.

    Bo_Ry has not 'disappeared' - he is a volunteer here, just like all of us, and it's up to him whether or not he contributes to your threads. Please don't comment on an individual's availability - it's entirely up to them when they visit and what they do whilst here.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  15. #15
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Find the index of substring in whole string in one cell

    Ok so next time i should ask about VBA in the same topic Ali?

    I know that he is volunteer

    I do not want to get just a solution, i have to understand this.

    Best,
    Jacek

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Find the index of substring in whole string in one cell

    Yes! You know very well that it's ONE THREAD PER ISSUE here.

    This thread is now closed. If you want to continue this discussion, then do so in the thread in the VBA section.

Closed 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 indexnumber of substring in string
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2021, 06:11 AM
  2. [SOLVED] ForLoop to Find string value as part of substring in another cell
    By skydivetom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2021, 05:19 PM
  3. Replies: 8
    Last Post: 03-09-2018, 11:39 AM
  4. Replies: 4
    Last Post: 02-22-2015, 09:52 AM
  5. [SOLVED] Find substring within a string, from a list
    By NotSwank in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-06-2014, 10:27 AM
  6. [SOLVED] Find the position of a substring in a string
    By nemo66ro in forum Excel General
    Replies: 6
    Last Post: 10-22-2012, 01:21 AM
  7. Find the sub string in column and copy the cell next to the substring
    By shrujan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2009, 11:00 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