+ Reply to Thread
Results 1 to 5 of 5

Search for a string in a Range

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Search for a string in a Range

    Hi,

    I have a list of words/codes. For each word/code, I am trying to identify if it appears in a range of cells (either as the entire cell or as a part of the cell). I'm not quite sure how to use the Find/Search/Countif functions when entering using an array, and I thought this would be an excellent means to find out how to fully utilise them!

    I've attached a representation of the database I'm working with.

    So to illustrate this scenario, the representative database comprises people who have attended a course which is run over 11 days.

    There is a list of names which I wish to check if they have attended the course on ANY day.

    The objectives....
    For each name on the list (Employee Table - Column M), I wish:
    a) To see if the person has attended any days (i.e. appear in the Reference Table range) - Output "Yes/No"
    b) To list which days they have attended - Output "01, 02, 03, 04" etc.
    c) To list the cell that the employee's name appears in (B2, B6, D7, D11)
    d) To count the number of the employee has attended.

    To make things a little more interesting (and to ask advice about how to best structure the database!), I've used two different layouts for the database.

    The first one (opt. 01), I have used a separate cell for each employee who attends on a particular day
    e.g. for Day one (Row 3), there were four attendees. These names appear in Cells B3:E3. The issue being is that if these are in an excel sheet, I need to reserve an unknown number of columns as I don't know the maximum number of people will be attending

    For the second layout (opt. 02), I have used one cell to store all employees who attended a particular day, separated by a comma.
    e.g. for Day one (Row 3), there were four attendees. These names appear in Cell B3: "DAVE, GRAEME, STUART, IAIN"
    This is more preferable (it doesn't really matter if there are one or a hundred attendees, they're all bunged into one cell/column.

    I would be very interested/grateful to understand how to search for the same output data required as above (a-d)

    Using VBA, I can then use the separator (in this case a comma) to enter the range simply into an array (Using a combo of Instr() and Mid() commands.


    I look forward to learning from your replies and thank you for taking the time to read my question! :o)

    Kind Regards, John





    p.s. I will be ultimately be doing this using VBA, but I think it would greatly improve my understanding (and hopefully many others!) of using formulae in Excel (such as Find/Search/Countif by array entre Ctrl+Enter(or not)!

    I'm not sure if all of these are possible through formulae alone, but which ever can be done would be really useful to see!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Search for a string in a Range

    The relatively difficult part about this will be the DAY(S) column, since you will most likely need a combination of multiple functions to achieve that result. However, for the rest the formulas are pretty straight forward:

    Sheet 2 - Cell S3 enter and drag down:

    Please Login or Register  to view this content.
    Sheet 2 - Cell U3 enter and drag down:

    Please Login or Register  to view this content.
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  3. #3
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Search for a string in a Range

    Thanks mcamahobt
    That nearly solves the problem - except if there was an attendee, "Johnathan", then this would provide a false positive for "John" on the list.

    I can see that this could be partially accounted for by introducing a "," into the search so:

    Please Login or Register  to view this content.
    would become
    Please Login or Register  to view this content.
    This would however cause a problem with names that weren't succeeded with a comma - such as singular attendees or the last one on the list, so presumably an additional condition would be required - such as an OR operator?


    Is there a way of using the Match function for a range spanning more than one column - For example for Option 01?

    I understand that the number of days may be an issue, but can the position of the first occurrence be returned (such as the Cell e.g."B3" and/or the Position in the cell of the first letter of the name - e.g. Character 7)

  4. #4
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Search for a string in a Range

    You are correct, there would be a conflict. This could be solved by adding the attendees last name, or an Option 01 operator as you suggested, to do a dual column match. And yes, the first position occurrence can be matched. Use this formula in T3 and drag down:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Search for a string in a Range

    Thanks again mcmahobt - this formula does indeed return the row#.

    Unfortunately with regards to issue of false positives "Johnathan" incorrectly being identified as a match for "John", this is not an option for my specific application. I used names as a simple way of illustrating the issue. So more appropriate values would be "AB1253" being incorrectly returned as a match for "AB125" which is an entirely different item, or similarly "Wheeltrim" being seen as a match for "Wheel"...

+ 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. Search A Range For Specific Text String
    By xybadog in forum Excel Formulas & Functions
    Replies: 29
    Last Post: 01-14-2015, 07:15 AM
  2. Search a range for any identical string in another range
    By Geoff. in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-31-2014, 02:34 PM
  3. String search in a Range - Userform
    By Ringhio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2014, 06:32 AM
  4. [SOLVED] Search for string with repeats in the searching range
    By Hallet in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-05-2012, 05:58 PM
  5. Replies: 24
    Last Post: 04-15-2009, 09:24 AM

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