Page 1 of 1

นำข้อมูลจาก combobox มาแสดงที่listbox

Posted: Fri Feb 12, 2021 4:48 pm
by muuearth
มือใหม่ครับฝากตัวด้วยครับ

ผมเลือกข้อมูลจาก combobox มาแสดงที่listboxครับ แต่อยากให้แสดงในlistbox แค่รายการที่เลือกแสดงตัวที่ซ้ำด้วยครับ
Private Sub ComboBox1_Change()
Dim i As Long
Dim sh As Worksheet
Dim LastRow As Long
Set sh = Sheets("Machine_list")
With Me.ListBox1
.ColumnHeads = True
.RowSource = "A3:G3"
End With
With Me.TextBox1
Me.TextBox1.Value = ""
With Me.TextBox2
Me.TextBox2.Value = ""
With Me.TextBox3
Me.TextBox3.Value = ""
With Me.TextBox4
Me.TextBox4.Value = ""
End With
End With
End With
End With
LastRow = sh.Range("B" & Cells.Rows.Count).End(xlUp).Row
For i = 4 To LastRow

If sh.Cells(i, "B").Value = (Me.ComboBox1) Or sh.Cells(i, "A").Value = Val(Me.ComboBox1) Then

Me.TextBox1 = sh.Cells(i, "B").Value
Me.TextBox2 = sh.Cells(i, "C").Value
Me.TextBox3 = sh.Cells(i, "F").Value
Me.TextBox4 = sh.Cells(i, "G").Value
ListBox1.RowSource = "B4:H598"
ListBox1.ColumnCount = 6
Me.ListBox1 = sh.Cells(i, "B").Value
End If
Next i
End Sub

รบกวนด้วยครับอาจารย์

Re: นำข้อมูลจาก combobox มาแสดงที่listbox

Posted: Sat Feb 13, 2021 3:11 pm
by logic
ขอแบบเป็นไฟล์เอ็กเซลล์ครับ

อ้อ...ดูกฎการใช้ฟอรัมข้อ 5 เรื่องการวางโค้ดในช่องถามตอบด้วยครับ 🙄