Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

Load image, and populate listbox by selecting dependent combobox

$
0
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?


Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>