+ Reply to Thread
Results 1 to 2 of 2

Don't want it to be necessary for exact string to be typed into search box.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2014
    Location
    SF
    MS-Off Ver
    Excel 2010
    Posts
    39

    Don't want it to be necessary for exact string to be typed into search box.

    Hey folks - I currently have code written for a search box. Unfortunately, it requires the exact string to be inputted in order for a row to be populated. In an ID, there could be "ID_AB_24" or "ID1_AB_32" or "AB_24". I would want for people to be able to simply type in AB_24 or AB_32 and still have it populated. Is there a way to do this? It's currently case-insensitive, and I'd like it to stay that way.

    Thanks!

    'Search function
    FindString = UCase(InputBox("Enter a Search value. If your original search does not work (i.e. AB_24) try another search (i.e. ab24 or ab024). Please wait a few seconds as the search takes time."))
        If Trim(FindString) <> "" Then
        
    
    
            
            'Set iterator
            Dim i As Integer
            i = 2
            
            'Loop over all items in column A
            For Each Cell In MasterColumn
                If UCase(CStr(Cell.Value)) = FindString Or UCase(CStr(Cell.Offset(0, BPOColumnIndex - 1).Value)) = FindString Or UCase(CStr(Cell.Offset(0, TestingColumnIndex - 1).Value)) = FindString Then
                    Matched = False

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Don't want it to be necessary for exact string to be typed into search box.

    Hi,

    You might want to try comparisons using the 'Like' command:
    Option Explicit
    Option Compare Text     'Needed for case insensitive comparisons (otherwise use 'Option Compare Binary')
    
    Sub TestLikeCommand()
    
      Dim bMatch As Boolean
      Dim sFindString As String
      Dim sActualData As String
      
      sActualData = "ID1_AB_32"
      
      
      sFindString = "AB_32"
      sFindString = "*" & sFindString & "*"
      bMatch = sActualData Like sFindString
      Debug.Print bMatch, sFindString, sActualData  'Output in Immediate Window (CTRL G in debugger)
    
      sFindString = "ab_32"
      sFindString = "*" & sFindString & "*"
      bMatch = sActualData Like sFindString
      Debug.Print bMatch, sFindString, sActualData  'Output in Immediate Window (CTRL G in debugger)
    
    End Sub
    For additional information see:
    http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx
    http://msdn.microsoft.com/en-us/library/8t3khw5f.aspx

    Lewis

+ 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 and Remove Exact String
    By Beaster in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-04-2013, 02:28 PM
  2. Search for EXACT string
    By jarochnrol in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2011, 11:39 AM
  3. Search Typed String and paste related content
    By deksiberu in forum Excel General
    Replies: 25
    Last Post: 04-13-2011, 10:33 PM
  4. exact search string type question
    By Noel Reichel in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-18-2007, 05:16 PM
  5. [SOLVED] a exact string search inquiry
    By vito in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-10-2006, 09:10 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