Get Text From Listbox To Textbox

  • Hi All,


    I have a Set of Strings in Sheet 1 - which i pull in to a List Box on Sheet 2.


    Now i have a Text Box in the same Sheet - I would like to have a macro for Text Box where when as and when i type in the Textbox i need only relevant strings to be in the Listbox.


    Ex: I i have INDIA,AUSTRALIA, AFRICA, USA, INDONASIA in my listbox - as i type a letter in the text box for example "I" i need only INDIA & INDONASIA to be in the list box and as i continue typing "INDO" i should be left out with only INDONASIA.


    Please help on this.


    Thanks

  • Re: Get Text From Listbox To Textbox


    HI.
    To populate the listbox when the workbook opens, put the following code in "thisworkbook" module :

    Code
    Private Sub Workbook_Open()
        Dim c
        With Sheets(1)
            .ListBox1.Clear
            For Each c In .Range([A1], [A65000].End(xlUp))
                .ListBox1.AddItem c
            Next c
        End With
    End Sub


    The code associated with the textbox is :

    Code
    Private Sub TextBox1_Change()
        With Sheets(1)
            .ListBox1.Clear
            For Each c In .Range([A1], [A65000].End(xlUp))
                If Left(c, Len(.TextBox1.Value)) = .TextBox1.Value Then
                    .ListBox1.AddItem c
                End If
            Next c
        End With
    End Sub


    The macro must be placed in the sheet module.
    HTH
    Daniel

    Regards.
    Daniel

  • Re: Get Text From Listbox To Textbox


    Thank for the Quick Response.


    But When I Place a List Box on the Sheet - I am not able to get the Reffernce to the Same in the Macro.


    It give me a run Time error - 438 "Object doesnt support this property or method.


    Just to Reiterate - I have placed a List box on Sheet1. - Should I Name the List box as i am not getting an option to do that?


    I am Facing one problem that is i am not able to place a textbox on the sheet as that property is disabled.


    Please help.


    Thanks



    Is th[hr]*[/hr] Auto Merged Post Until 24 Hrs Passes;[dl]*[/dl]I am Sorry guys I worked arround it and found the Answer - Thanks a Lot.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!