Tôi thử gán RowSource bằng Array thay vì dùng AdFi khi có những điều kiện thỏa.
Các bạn giúp bổ sung và hoàn thiện hơn phần gán RowSource trên UserForm.
Xin cám ơn.
Code của Form.
Các bạn giúp bổ sung và hoàn thiện hơn phần gán RowSource trên UserForm.
Xin cám ơn.
Code của Form.
PHP:
Private Sub CB_Tim_Click()
With Application
.ScreenUpdating = False
End With
Dim endR As Long, i As Long, s As Long, k As Long
Dim Arr(), arrKQ()
Dim MaHHTim As String
With Sheets("DMHH")
endR = .Cells(65000, 1).End(xlUp).Row
Arr = .Range(.Cells(2, 1), .Cells(endR, 5)).Value
End With
ReDim arrKQ(1 To endR, 1 To 5)
s = 0
MaHHTim = Me.NhomHang.Value
For i = 1 To UBound(Arr)
If InStr(Arr(i, 1), UCase(MaHHTim)) Then
s = s + 1
For k = 1 To 5
arrKQ(s, k) = Arr(i, k)
Next k
End If
Next i
If s = 0 Then
MsgBox "No Ma"
Me.NhomHang.SetFocus
With Me.MHList
.ColumnCount = 5
.List = Arr
End With
End If
With Me.MHList
.Clear
.ColumnCount = 5
.List = arrKQ
End With
With Application
.ScreenUpdating = False
End With
Erase Arr(), arrKQ()
End Sub
Private Sub Nhap_Click()
Dim i As Long, j As Long, endR As Long, k As Long, SelectItem As Long
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
With Sheets("PBH")
endR = .Cells(65000, 1).End(xlUp).Row
j = endR + 1
For i = 0 To MHList.ListCount - 1
If MHList.Selected(i) Then
For k = 1 To 5
.Cells(j, k) = MHList.List(i, k - 1)
Next k
j = j + 1
SelectItem = 1
End If
Next i
End With
If SelectItem = 0 Then
MsgBox "Ban da khong chon ten nao trong danh sach !"
End If
Unload Me
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Private Sub NhomHang_AfterUpdate()
CB_Tim.SetFocus
End Sub
Private Sub Thoat_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim endR As Long
Dim Arr()
With Sheets("DMHH")
endR = .Cells(65000, 1).End(xlUp).Row
Arr = .Range(.Cells(2, 1), .Cells(endR, 5)).Value
End With
With Me.MHList
.ColumnCount = 5
.List = Arr
End With
Erase Arr
End Sub
File đính kèm
Lần chỉnh sửa cuối: