VBA: Linked txt box

  • XL-Dennis sent me this code to link a combo box inside a userform to data inside the A column on a sheet:

    Private Sub UserForm_Initialize()
    Dim wbBook As Workbook
    Dim wsSheet As Worksheet
    Dim rnData As Range
    Dim vaData As Variant

    Set wbBook = ThisWorkbook
    Set wsSheet = wbBook.Worksheets("Blad1")

    With wsSheet
    Set rnData = .Range(.Range("A1"), .Range("A65536").End(xlUp))
    End With

    vaData = rnData.Value

    With Me.ComboBox1
    .List = vaData
    .ListIndex = -1
    End With

    End Sub

    This works great. Now I would like it to link the data from column B into an empty txt box dependng on what is chosen in the combo box e.g

    A B
    red light
    blue dark
    yellow light
    green light

    Column A is the combo box and column b is the empty txt box.

    What I want to happen is what is chosen in column A its corresponding data in column b automatically fills in inside the txt box.

    So if you choose red in the combo box, light will appear in the empty txt box.

    The txt box will always b changing depending on what is selected from the combo box.

    Can someone help me ?

Participate now!

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