Forum Discussion

oteixeira62's avatar
oteixeira62
Copper Contributor
Jan 15, 2023
Solved

Populate textbox with cell value selected in listbox in a different column

Hello to all, I’m trying to adapt the VBA code to populate the userform TextBox2 with a value located in a non-contiguous, different column, as explained in the picture bellow.   This is the...
  • HansVogelaar's avatar
    Jan 15, 2023

    oteixeira62 

    Try this version of ListBox1_Click:

    Private Sub ListBox1_Click()
        Dim s As String
        If Me.ListBox1.ListIndex >= 0 Then    'User has selected
            s = Application.VLookup(Me.ListBox1.Value, Worksheets("Tabelas").Range("A:H"), 8, False)
            Me.TextBox1.Value = s
        End If
    End Sub

Resources