Page 1 of 1

VBA COMBO BOX ต้องการข้อมูลแค่บางอัน (userform)

Posted: Thu Apr 18, 2019 11:14 am
by choinat
พอดีผมมี combo box แล้วต้องการดึงข้อมูลมาแค่บางตัว
อย่างเช่น
นาย ก อยู่ ภาค 1
นาย ข ภาค 2
นาย ค ภาค 1
(ข้อมูลอยู่ Row เดียวกัน)

combobox ของผมจะเป็นชื่อคน แต่ต้องการคนที่มาแสดงเป็นแค่ภาค 1

Code: Select all

Private Sub NameMTD_Change()


Set sh = ThisWorkbook.Sheets("DEP")

Dim N As Long, lastrow As Long
lastrow = Sheets("DEP").Range("A" & Rows.Count).End(xlUp).Row
For N = 2 To lastrow
If Sheets("DEP").Cells(N, "A").Value = (Me.NameMTD) Or Sheets("DEP").Cells(N, "A").Value = Val(Me.NameMTD) Then
Me.listmtd2 = Sheets("DEP").Cells(N, "B").Value
Me.listmtd3 = Sheets("DEP").Cells(N, "C").Value
Me.listmtd4 = Sheets("DEP").Cells(N, "D").Value
Me.listmtd5 = Sheets("DEP").Cells(N, "E").Value
Me.listmtd6 = Sheets("DEP").Cells(N, "F").Value
Me.listmtd7 = Sheets("DEP").Cells(N, "G").Value
Me.listmtd8 = Sheets("DEP").Cells(N, "H").Value
Me.listmtd9 = Sheets("DEP").Cells(N, "I").Value
Me.listmtd10 = Sheets("DEP").Cells(N, "J").Value
Me.listmtd11 = Sheets("DEP").Cells(N, "K").Value
Me.listmtd12 = Sheets("DEP").Cells(N, "M").Value
Me.listmtd13 = Sheets("DEP").Cells(N, "P").Value
Me.listmtd14 = Sheets("DEP").Cells(N, "Q").Value
Me.listmtd15 = Sheets("DEP").Cells(N, "R").Value
Me.listmtd16 = Sheets("DEP").Cells(N, "S").Value


End If
Next N


   End Sub

Code: Select all

Private Sub NameMTD_DropButtonClick()

Set sh = ThisWorkbook.Sheets("DEP")
Dim N As Long, lastrow As Long
lastrow = Sheets("DEP").Range("A" & Rows.Count).End(xlUp).Row
If Me.NameMTD.ListCount = 0 Then
For N = 6 To lastrow
Me.NameMTD.AddItem Sheets("DEP").Cells(N, "A").Value
Next N
End If


End Sub

Re: VBA COMBO BOX ต้องการข้อมูลแค่บางอัน (userform)

Posted: Thu Apr 18, 2019 1:23 pm
by logic
แนบไฟล์ .xlsm มาด้วยครับ

Re: VBA COMBO BOX ต้องการข้อมูลแค่บางอัน (userform)

Posted: Thu Apr 18, 2019 3:18 pm
by choinat
นี้ครับไฟล์
calllist_Customer04112019 TEST.xlsm
(35.32 KiB) Downloaded 21 times

Re: VBA COMBO BOX ต้องการข้อมูลแค่บางอัน (userform)

Posted: Thu Apr 18, 2019 3:36 pm
by logic
คลิกปุ่ม Form แล้วค้างตรง Private Sub UserForm_Activate() ครับ

ถ้าหายค้างแล้วช่วยบอกด้วยว่าคอมโบบ็อกซ์ชื่ออะไร เอาค่าอะไรมาใส่ ใช้หลักการอะไรในการเลือกครับ