0

I'm trying to load img from folder path, and populate listbox by dependent combobox selection

so far I have this code attached below

Private Sub ComboBox3_Change()

Private Sub UserForm_Initialize()
    ComboBox1.RowSource = "EngType"
    ComboBox2.Value = "Please Select Engine Type"

End Sub
Private Sub ComboBox1_Change()

    If ComboBox1.Text = "IF" Then
        ComboBox2.Value = ""
        ComboBox2.RowSource = "IF"

    ElseIf ComboBox1.Text = "GMT" Then

        ComboBox2.RowSource = "GMT"

    End If
End Sub

Private Sub ComboBox2_Change()

    Dim dtRange As Range, itm As Variant, i As Long, ImgAdrs As String

        ImgFile = ThisWorkbook.Path & "\IMG\IF"

     If ComboBox2.Value <> "Please Select Engine Type" Then
                UserForm.Image1.Picture = LoadPicture(ImgFile & ComboBox2.Text & ".jpg")
            Else
                UserForm.Image1.Picture = LoadPicture(ThisWorkbook.Path & "\IMG\IF\W_logo_color_pos_RGB.jpg")

            End If
    With Sheets("UserForm")

        If ComboBox1.Text = "IF" Then
            Set dtRange = .Range("J2:J2000").Find(What:=Me.ComboBox2.Value)

            If Not dtRange Is Nothing Then

                For Each itm In .Range("K2:N2000")
                    ListBox1.AddItem itm
                Next
            End If


        ElseIf ComboBox1.Text = "GMT" Then
            Set dtRange = .Range("E2:E2000").Find(What:=Me.ComboBox2.Value)

            If Not dtRange Is Nothing Then
                For Each itm In .Range("F2:H2000")
                    ListBox1.AddItem itm
                Next
            End If

        End If

    End With

End Sub

it populates a listbox but all the list populates in first column and I'm kept getting error from img when I select second combobox

any idea?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Billy Hong
  • 11
  • 2
  • 1
    Which error? In which line of code? Please be more precise describing what is going wrong (also see [mcve]). Also *"any idea?"* is not a real question you will get a good answer to (see [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/a/284237/3219613)). Please [edit] and improve your question. – Pᴇʜ Dec 13 '19 at 07:26
  • If it's your main concern to populate all columns in your list, see [Populate ListBox with multiple columns](https://stackoverflow.com/questions/47528558/vba-excel-populate-listbox-with-multiple-columns/47531440#47531440) to get an idea of the array method; `ListBox1.AddItem` adds rows one by one without any entry, `Listbox1.AddItem itm` only enters the cell content to the first column of each row; as you literally iterate throug each cell you get one single column. Suggest to try again and to break down your issues to smaller, reproducible parts by reedit or a new question :-) – T.M. Dec 14 '19 at 15:56
  • Thanks @Pᴇʜ, I will try to improve my quality of question next time. – Billy Hong Dec 18 '19 at 03:09
  • 1
    Thanks @T.M. solved it using advance filter, and update the value in listbox – Billy Hong Dec 18 '19 at 03:09

0 Answers0