snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Private Sub CommandButton1_Click()
Dim i As Long
Me.ListBox1.Clear
Me.ListBox1.AddItem
For a = 1 To 7
Me.ListBox1.List(0, a - 1) = Sheet1.Cells(1, a)
Next a
Me.ListBox1.Selected(0) = True
'For List Box fill
For i = 2 To Sheet1.Range("A100000").End(xlUp).Offset(1, 0).Row
For j = 1 To 7
H = Application.WorksheetFunction.CountIf(Sheet1.Range("A" & 2, "G" & i), _
Sheet1.Cells(i, j))
If H = 1 And LCase(Sheet1.Cells(i, j)) = LCase(Me.Range("D2").Value) Or H = 1 And _
Sheet1.Cells(i, j) = Val(Me.Range("D2").Value) Then
Me.ListBox1.AddItem
For x = 1 To 7
Me.ListBox1.List(ListBox1.ListCount - 1, x - 1) = Sheet1.Cells(i, x)
Next x
End If
Next j
Next i
End Sub
'Other code
'For List Box fill
For i = 2 To Sheet1.Range("A100000").End(xlUp).Row
If Sheet1.Cells(i, 2).Value = Sheet2.Cells(2, 4).Value Then
Me.ListBox1.AddItem
For x = 1 To 7
Me.ListBox1.List(ListBox1.ListCount - 1, x - 1) = Sheet1.Cells(i, x)
Next x
End If
Next i
End Sub
'Other code
Dim i As Long, j As Long
Dim arr(0, 23) As Variant
Me.ListBox1.Clear
Me.ListBox1.AddItem
For a = 0 To 23
arr(0, a) = Sheet1.Cells(1, a + 1).Value
' Me.ListBox1.List(0, a - 1) = Sheet1.Cells(1, a)
Next a
Me.ListBox1.ColumnCount = 24
Me.ListBox1.List = arr
'Other code
Private Sub CommandButton2_Click()
Dim i As Integer
For i = 1 To Sheet1.Range("A" & Rows.Count).End(xlUp).Row
If Sheet1.Cells(i, 2).Value = Sheet2.ListBox1.List(ListBox1.ListIndex) Then
Sheet1.Rows(i).EntireRow.Delete
End If
Next i
End Sub