Thread: [Solved] Listbox showing null
View Single Post
 
Old 03-14-2020, 09:39 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Can we assume that this is part of a userform? It is not clear why you need two list boxes. Your message suggests that you should use a list box and a text box, thus


Code:
Private Sub ListBox1_Click()
Dim sMyStr As String
    sMyStr = ListBox1.value
    If sMyStr = "P21" Then
        TextBox1.Text = "41"
    ElseIf sMyStr = "P69" Then
        TextBox1.Text = "31"
    ElseIf sMyStr = "P62" Then
        TextBox1.Text = "11"
    ElseIf sMyStr = "P64" Then
        TextBox1.Text = "42"
    Else
        TextBox1.Text = ""
    End If
End Sub

Private Sub UserForm_Initialize()
Dim i As Integer
    With ListBox1
        For i = 21 To 69
            .AddItem "P" & i
        Next i
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote