snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
คือผมต้องการให้แสดงหลายค่า เช่น ถ้าผมเลือก "a" ใน (combobox1) แล้ว "a" match กับ "1" ในคอลัมน์ A แล้ว จะให้ "1" ในคอลัมน์ F math กับ "ก,ด,พ,ผ,ป" ในคอลัมน์ G แล้วแสดงทุกค่าใน (combobox2) ควรทำอย่างไรดีครับ ลองทำแล้วมันขึ้นแค่ค่าเดียว คือ ก ตัวแรก
Private Sub ComboBox1_Change()
Dim i, j As Integer
With Application.WorksheetFunction
i = Val(.Index(Sheets("sheet1").Range("a2:a10000"), .Match(Me.ComboBox1, Sheets("Sheet1").Range("b2:b10000"), 0)))
ComboBox2.Value = Application.WorksheetFunction.VLookup((i), Sheets("Sheet1").Range("F2:G10000"), 2, False)
End With
End Sub
Private Sub ComboBox1_Change()
Dim i, j As Integer
Dim rall As Range, r As Range
With Sheets(1)
Set rall = .Range("f2", .Range("f" & .Rows.Count).End(xlUp))
End With
With Application.WorksheetFunction
i = Val(.Index(Sheets("sheet1").Range("a2:a10000"), .Match(Me.ComboBox1, Sheets("Sheet1").Range("b2:b10000"), 0)))
For Each r In rall
If r.Value = i Then
ComboBox2.AddItem r.Offset(0, 1)
End If
Next r
End With
End Sub
Private Sub ComboBox1_Change()
Dim i, m, n As Integer
Dim lRow As Long
With Application.WorksheetFunction
i = Val(.Index(Sheets("sheet1").Range("a2:a10000"), .Match(Me.ComboBox1, Sheets("Sheet1").Range("b2:b10000"), 0)))
End With
On Error Resume Next
m = Application.WorksheetFunction.Match(i, Range("F1:F200"), 0)
n = Application.WorksheetFunction.Match(i, Range("F1:F200"), 1)
With Sheets("Sheet1")
ComboBox2.RowSource = .Range(.Cells(m, 7), .Cells(n, 7)).Address
End With
End Sub
'Other code
ComboBox2.Clear
With Application.WorksheetFunction
i = Val(.Index(Sheets("sheet1").Range("a2:a10000"), .Match(Me.ComboBox1, Sheets("Sheet1").Range("b2:b10000"), 0)))
For Each r In rall
If r.Value = i Then
ComboBox2.AddItem r.Offset(0, 1)
End If
Next r
End With