Text boxes populating from Combo box

gadrummer65

New Member
Joined
Mar 6, 2014
Messages
9
Hello,
I have a code that mostly works. The only problem i am having is when the text boxes populate, they always populate the last item in my list, and not what i am clicking on. Any help would be greatly appreciated.

Code:
Private Sub ComboBox2_Click()

    Dim LR As Long
    Dim fRng As Range

    With Sheets("Hotels")
        LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious).Row

        Set fRng = .Range("A2:A" & LR)

        If Not .Aut**ilterMode Then
            .Range("A3").Aut**ilter
        End If
        .Range("A3:A" & LR).Aut**ilter Field:=1, Criteria1:=Me.ComboBox2.Value
        Me.tbResCol1.Value = .Aut**ilter.Range.**fset(1).SpecialCells(xlCellTypeVisible).Cells(0, 2).Value
        Me.tbResCol2.Value = .Aut**ilter.Range.**fset(1).SpecialCells(xlCellTypeVisible).Cells(0, 3).Value
        Me.tbResCol3.Value = .Aut**ilter.Range.**fset(1).SpecialCells(xlCellTypeVisible).Cells(0, 4).Value
        Me.tbResCol4.Value = .Aut**ilter.Range.**fset(1).SpecialCells(xlCellTypeVisible).Cells(0, 5).Value
        Me.tbResCol5.Value = .Aut**ilter.Range.**fset(1).SpecialCells(xlCellTypeVisible).Cells(0, 6).Value
        .Aut**ilterMode = False
    End With
    Me.ComboBox1.Enabled = True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
What exactly are you trying to do? It seems a very complicated way to populate textboxes.

Please try sharing a dummy file using OneDrive, DropBox or similar
 
Upvote 0
On this Forum the only way is to use a File sharing site like DropBox. Post a link here.
 
Upvote 0
What does the AutoFilter find?

Is there more than one row?

I think possibly AdvancedFilter may be a better option.
 
Upvote 0
Replace your code with this

Code:
Private Sub ComboBox2_Click()




    Dim fRng As Range, fCl As Range
    Dim lRw As Long
    Dim iX As Integer


    With Worksheets("Hotels")
        Set fRng = .Range("B2").CurrentRegion.Offset(1).Columns(1)
    End With


    With fRng
        Set fCl = .Find(Me.ComboBox1.Value)
        If Not fCl Is Nothing Then
            lRw = fCl.Row - 1
            For iX = 1 To 8
                Me("tbResCol" & iX).Value = .Cells(lRw, iX).Value
            Next iX
        End If
    End With


    Me.ComboBox1.Enabled = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,215
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top