snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Dim Y As Integer,Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Sheet1.LB1
.Clear
.ColumnCount = 2
For Y = 0 To LR - 1
.AddItem
.Column(0, Y) = Cells(Y + 1, 1)
.Column(1, Y) = Cells(Y + 1, 2)
Next
End With
Private Sub CommandButton1_Click()
Dim Y As Integer, LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Sheet1.LB1
.Clear
.ColumnCount = 3
For Y = 1 To LR
For i = 0 To 2
.AddItem
.Column(i, Y - 1) = Cells(Y, i + 1)
Next i
Next Y
End With
End Sub
Private Sub CommandButton1_Click()
Dim Y As Integer: Dim LR As Long
Dim i As Integer
LR = Range("A" & Rows.Count).End(xlUp).Row
With Sheet1.LB1
.Clear
.ColumnCount = 3
.ColumnWidths = "20;130;30"
For Y = 1 To LR
If Cells(Y, 2).Value = "A" Then
.AddItem
.Column(0, i) = Cells(Y, 1)
.Column(1, i) = Cells(Y, 2)
.Column(2, i) = Cells(Y, 3)
i = i + 1
End If
Next
End With
End Sub