+ Reply to Thread
Results 1 to 9 of 9

Search each row for string, put result in last column

  1. #1
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Question Search each row for string, put result in last column

    Hi All

    I am hoping someone can help, as the more I look for a solution the more confused I get about loops and find().

    Is it possible to use VBA to search through rows of data for a specific string (say 'Apples') and then insert a boolean result in the final column. It'll be for datasets no more than 300-1500 rows long, 15-20 columns wide

    Picture2.png

    Any advice would massively appreciated
    All the best
    Vicky
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Search each row for string, put result in last column

    Will this work for you?
    =ISNUMBER(MATCH("apples",C5:H5,0))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,409

    Re: Search each row for string, put result in last column

    (Using your posted file for cell references) Another formula you can try...

    =COUNTIF(C5:H5,"apples")>0

  4. #4
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: Search each row for string, put result in last column

    Thank you both for the fast replies.

    Is there any way to achieve this with VBA so that there are no formulas on the worksheet?

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this demonstration …


    Even for a dumb VBA way the better is to use a smart table formula :

    PHP Code: 
    Sub Demo1()
         
    Dim C%, F$
        
    With Sheets("Sheet1").ListObjects(1)
             
    = .ListColumns.Count
             F 
    "=COUNTIF(" & .Name "[@[" & .Range(2).Text "]:[" & .Range(1).Text _
                 
    "]],""" Replace(.Range(C).Text"Has """) & """)>0"
            
    With .DataBodyRange.Columns(C):  .Formula F:  .Formula = .Value2:  End With
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Search each row for string, put result in last column

    Happy to help and thanks for the feedback

  7. #7
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: Search each row for string, put result in last column

    Oh wow! Thank you Marc

    This is superb. So much more than I hoped for. It works no matter where the table is positioned and it searches for whatever word I put in the final column title. Amazing stuff.

    But I'm having a little trouble implementing it in my workbook. After a bit of testing I realised the code doesn't like these characters in my column titles ":" and "[ ]". Is there any way to get around this without renaming the columns? Would double quote marks mark?

    I know renaming the columns should be simpler but I have other VBA scripts that are reliant on the column name layouts (they update pivot table categories in 10 other sheets) so ideally trying not too. See attached revised doc

    Picture2.png

    Thanks again
    All the best
    V
    Attached Files Attached Files
    Last edited by vwhite; 06-09-2020 at 07:29 AM.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Search each row for string, put result in last column

    (removed …)
    Last edited by Marc L; 06-09-2020 at 08:05 AM.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Search each row for string, put result in last column


    To understand the Excel table basic syntax start to enter a COUNTIF formula then using the mouse
    to select the first and the last cells so you must see how those characters are escaped with a quote.
    For each header you can use the VBA Replace function to add a quote for those characters
    or use the Address property of a cell rather than the Excel table syntax
    or better just renaming the headers, yes I know, obviously too obvious …

+ 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] Search a row for a string and return result
    By Margate in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-30-2019, 08:08 AM
  2. Search column for string and date then search adjacent cell and pop up message
    By ftwobtwo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2014, 09:55 AM
  3. Replies: 1
    Last Post: 09-11-2014, 10:59 AM
  4. Search column for string and return every row with that string in new sheet
    By myers601 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2012, 06:02 PM
  5. [SOLVED] Search for string across header row, then search for another string down found column
    By TucsonJack in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:09 PM
  6. Replies: 1
    Last Post: 07-26-2011, 06:48 AM
  7. How do to search for a string in excel across all rows/columns and save the result?
    By akondeti in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-07-2006, 07:16 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