+ Reply to Thread
Results 1 to 5 of 5

VBA function to search partial string and return value

Hybrid View

  1. #1
    Registered User
    Join Date
    01-27-2014
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    16

    VBA function to search partial string and return value

    Hi all,

    I'm trying to come up with a VBA function that would return cell values based on another cell value.

    I can do this by comparing a range (column of cells) with the cell value to match and then return the value of the cell next to it.

    For instance,

    The function should search a column for partial text, as follows:

    TS ID PDT ID
    TS 1.1 PDT 1
    TS 1.2 PDT 2
    TS 1.3 PDT 3
    TS 2.1 PDT 4
    TS 2.2 PDT 5
    TS 3.1 PDT 6
    TS 3.2 PDT 7

    In the above table, the function should for partial text and return string as follows:

    TS covered PDTs
    TS 1.1, TS 1.2, TS 1.3 PDT 1, PDT 2, PDT 3
    TS 2.1, TS 2.2 PDT 4, PDT 5
    TS 3.1, TS 3.2 PDT 6, PDT 7

    So basically I am searching for partial text TS 1. and so on
    Last edited by gorelordz; 01-28-2014 at 10:28 AM.

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: VBA function to search partial string and return value

    I hope this helps. Run the Macro
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-27-2014
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: VBA function to search partial string and return value

    Hey rcm,

    Thanks for the assistance. But, if i add more entries to the source table, the outcome seems to get overwritten rather than appended. Why is that?

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: VBA function to search partial string and return value

    Sub partialsearch()
    
    rmax = Range("a" & Rows.Count).End(xlUp).Row
    r2 = Range("d" & Rows.Count).End(xlUp).Row + 1  'correct this one
    b = 2
    l = 3...
    sorry for the oversight, please correct the r2 initial value so it adds any additional rows at the bottom

  5. #5
    Registered User
    Join Date
    01-27-2014
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: VBA function to search partial string and return value

    Perfect! Clean as a whistle! Thank you rcm

+ 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 in a listbox on partial string as you type
    By Flyb in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-11-2015, 08:24 PM
  2. [SOLVED] need to do Partial name search and return the value against the partial name
    By Kiran Kurapati in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2013, 09:40 AM
  3. [SOLVED] Search Table by Partial String Criteria, No Arrays
    By daffodil11 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-30-2013, 10:13 AM
  4. [SOLVED] Vlookup, Match (Search or Find) partial string within string in a Cell
    By dluhut in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-28-2013, 12:40 PM
  5. Return Value Based On Partial Text String
    By JonnyBoy333 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-12-2011, 09:29 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