Private somuc As Long, Arr(), chisochon()
Private Sub CB_Tim_Click()
Dim lastRow As Long, r As Long, c As Long, count As Long
Dim arrKQ(), chiso() As Long
Dim MaHHTim As String, timthay As Boolean
MHList.Clear
count = 0
MaHHTim = UCase(Me.NhomHang.Value)
For r = 1 To UBound(Arr) - 1
timthay = InStr(UCase(Arr(r, 1)), MaHHTim) > 0
If Not timthay Then
timthay = InStr(UCase(Arr(r, 2)), MaHHTim) > 0
If Not timthay Then timthay = InStr(UCase(Arr(r, 3)), MaHHTim) > 0
End If
If timthay Then
count = count + 1
ReDim Preserve chiso(1 To count)
chiso(count) = r
End If
Next r
If count Then
ReDim arrKQ(1 To count, 1 To 4)
For r = 1 To count
c = chiso(r)
arrKQ(r, 1) = Arr(c, 1)
arrKQ(r, 2) = Arr(c, 2)
arrKQ(r, 3) = Arr(c, 3)
arrKQ(r, 4) = c
Next r
MHList.List = arrKQ
Else
MsgBox "No noi dung"
End If
End Sub
Private Sub cmdChon_Click()
Dim k As Long
For k = 0 To MHList.ListCount - 1
If MHList.Selected(k) Then
somuc = somuc + 1
ReDim Preserve chisochon(1 To somuc)
chisochon(somuc) = MHList.List(k, 3)
End If
Next
MHList.Clear
NhomHang.Value = Empty
NhomHang.SetFocus
End Sub
Private Sub cmdNhap_Click()
Dim lastRow As Long, k As Long, r As Long, result()
If somuc < 1 Then Exit Sub
ReDim result(1 To somuc, 1 To 3)
lastRow = ThisWorkbook.Worksheets("TH").Cells(Rows.count, "AH").End(xlUp).Row + 1
For k = 1 To UBound(chisochon)
r = chisochon(k)
result(k, 1) = Arr(r, 1)
result(k, 2) = Arr(r, 2)
result(k, 3) = Arr(r, 3)
Next k
ThisWorkbook.Worksheets("TH").Cells(lastRow, "AH").Resize(UBound(result), UBound(result, 2)).Value = result
somuc = 0
Erase chisochon
MHList.Clear
NhomHang.Value = Empty
NhomHang.SetFocus
End Sub
Private Sub Thoat_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim lastRow As Long
With Sheets("Note1")
lastRow = .Cells(Rows.count, "H").End(xlUp).Row
Arr = .Range("H10:J" & lastRow + 1).Value
End With
With Me.MHList
.ColumnCount = 3
.List = Arr
End With
somuc = 0
Erase chisochon
NhomHang.SetFocus
End Sub
Private Sub NhomHang_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 40 Then MHList.SetFocus
End Sub
Private Sub CB_Tim_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 40 Then MHList.SetFocus
End Sub