+ Reply to Thread
Results 1 to 3 of 3

Userform Combobox selection populates wrong data in the textboxes

Hybrid View

  1. #1
    Registered User
    Join Date
    08-09-2010
    Location
    Riyad
    MS-Off Ver
    Excel 2007
    Posts
    2

    Userform Combobox selection populates wrong data in the textboxes

    Hi

    I have a userform with several textboxes and a combobox. The combobox list is sorted alphabetically by a code, while the worksheet is not. I am using the change event of the combobox to populate the textboxes with the values from the worksheet, based on the combobox value. However, the textboxes are not populated properly. I am sure that there is something wrong with my code, which I can't rectify. Please help. The file is attached.
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Userform Combobox selection populates wrong data in the textboxes

    Since you've sorted the data in the combobox you can't use it's ListIndex to find the row of data you want.

    You'll need some other method.

    Try this which works with your sample data as long as you change the BoundColumn of cboFirstname to 1.
    Private Sub cboFirstName_Change()
    Dim row_nunber As Integer
    
        If cboFirstName.ListIndex <> -1 Then
    
            row_number = Application.Match(cboFirstName.Value, Worksheets("Address Book").Range("A:A"), 0)
            With Worksheets("Address Book")
            
                TextBox1.Text = .Cells(row_number, 1).Value
    
                TextBox2.Text = .Cells(row_number, 2).Value
    
                TextBox3.Text = .Cells(row_number, 3).Value
    
                TextBox4.Text = .Cells(row_number, 4).Value
    
                TextBox5.Text = .Cells(row_number, 5).Value
    
                TextBox6.Text = .Cells(row_number, 6).Value
    
                TextBox7.Text = .Cells(row_number, 7).Value
    
            End With
    
    
            cboFirstName.SetFocus
    
        End If
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-09-2010
    Location
    Riyad
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Userform Combobox selection populates wrong data in the textboxes

    Dear Norie
    It's working perfectly. Thank a lot.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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