+ Reply to Thread
Results 1 to 5 of 5

VBA - Adding Search to Listbox based on Textbox value

  1. #1
    Registered User
    Join Date
    03-20-2013
    Location
    chicago
    MS-Off Ver
    Excel 2010
    Posts
    10

    VBA - Adding Search to Listbox based on Textbox value

    I am having hard time figuring out filtering. I have long list and I want to add search to that list and wanted to give me list of closets option to select from but, struggling with the code.

    *****************

    Below is link to original post, i borrowed some ideas from:
    http://www.excelforum.com/excel-prog...ml#post3796860

    *****************

    Link to file:
    http://we.tl/1ZUqIOjrTk

    thanks in advance for you help!
    Nimesh
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA - Adding Search to Listbox based on Textbox value

    1. If you have a rowsource specified in the listbox properties, you can't modify it. You'll get a strange, unrelated error.

    2. Filter is expecting a 1-dimensional array. The named range is two dimensional.

    3. From the cell contents, it looks like you want the code returned? Be sure to specify which column you want returned BY DEFAULT by specifying the Bound property. If you want both, then you'll have to return it using List or Column.

    Please Login or Register  to view this content.
    Last edited by Tinbendr; 08-09-2014 at 05:08 AM.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    03-20-2013
    Location
    chicago
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA - Adding Search to Listbox based on Textbox value

    Tinbendr, this is awesome!
    Yes i do want both cells to return, Code#(A) and category(b). Is it possible to copy both in single cell and add 'dash (-)' between the two?
    For Example: 00 4100-Bid Form

    Thank you again,
    Nimesh

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA - Adding Search to Listbox based on Textbox value

    And is there a specific cell you want that returned to? Or maybe the next available cell in a column? Do you want to be able to select more than one?

    To return to the activecell.
    Please Login or Register  to view this content.
    Last edited by Tinbendr; 08-09-2014 at 12:45 PM.

  5. #5
    Registered User
    Join Date
    03-20-2013
    Location
    chicago
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA - Adding Search to Listbox based on Textbox value

    Quote Originally Posted by Tinbendr View Post
    And is there a specific cell you want that returned to? Or maybe the next available cell in a column? Do you want to be able to select more than one?

    To return to the activecell.
    Please Login or Register  to view this content.
    Tinbendr,
    Yes, I do want it returned in the Avtivecell and I had that part working but, I like your code better. It gives me more control. Take a look at the full code below with your latest Activecell code.
    This works great, thanks again.

    -Nimesh

    ****************

    Private Sub UserForm_Initialize()
    'You could just hard code in in the properties,
    'but I prefer to control it.
    Me.ListBox1.RowSource = "CSI"
    End Sub

    Private Sub TextBox1_Change()
    Dim WS As Worksheet
    Dim LastRow As Long
    Dim A As Long
    Dim C As Range, Firstaddress As String

    If Len(Me.TextBox1) = 0 Then
    Me.ListBox1.RowSource = "csi"
    Else
    Me.ListBox1.RowSource = ""

    Set WS = Worksheets("Sheet1")

    With WS
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    With .Range("a1:B" & LastRow)
    Set C = .Find(Me.TextBox1, LookIn:=xlValues, lookat:=xlPart)
    If Not C Is Nothing Then
    Firstaddress = C.Address
    Do
    Me.ListBox1.AddItem WS.Range("A" & C.Row)
    Me.ListBox1.Column(1, Me.ListBox1.ListCount - 1) = WS.Range("B" & C.Row)
    Set C = .FindNext(C)
    Loop While Not C Is Nothing And C.Address <> Firstaddress
    End If
    End With
    End With
    End If
    End Sub

    Private Sub CommandButton1_Click()
    ActiveCell.Value = Me.ListBox1.Value & "-" & _
    Me.ListBox1.Column(1, Me.ListBox1.ListIndex)
    'ActiveCell.Value = ListBox1.Value
    'Unload the userform
    Unload Me
    End Sub

    ******************************

+ 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] VBA userform search for listbox entry based on Textbox value
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 03-12-2015, 08:29 AM
  2. Search listbox from textbox
    By zplugger in forum Excel General
    Replies: 12
    Last Post: 08-23-2012, 08:11 PM
  3. [SOLVED] Textbox to search listbox
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2012, 08:25 AM
  4. Textbox search and display results in listbox
    By AirBrun in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 08-02-2012, 01:22 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