Option Explicit
Private Sub OpenLb2(Cot, Rg As Range)
Dim endRg As Range, ChCl, SoCot
If Rg.Column = 3 Then SoCot = 3 Else SoCot = 1
With Me.Lb2
.ColumnCount = SoCot
.ColumnWidths = IIf(SoCot = 1, "250", "70;200;50")
.Width = IIf(SoCot < 2, 255, 325)
ChCl = Choose(Cot, "AH", "B", "G", "L", "Q", "V", "AA", 0, 0, 0, 0, 0, 0)
Set endRg = Sheet2.Cells(65000, ChCl).End(xlUp)
.ListFillRange = Sheet2.Name & "!" & Sheet2.Range(Sheet2.Cells(3, ChCl), endRg).Resize(, SoCot).Address
.Height = IIf(.ListCount > 10, 144, .ListCount * 14.7 + 10)
.Top = Rg.Top
.Left = Rg.Left
.Visible = True
.Activate
End With
End Sub
'----------------------------------
Private Sub Lb1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim Cl2
Lb1.Visible = False
Cl2 = IIf(Lb1.ListIndex < 1, 2, Lb1.ListIndex + 2)
OpenLb2 Cl2, ActiveCell
End Sub
'--------------------------------------
Private Sub Lb1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim Cl1, Cl2
If KeyCode = 13 Then
KeyCode = 0
Lb1.Visible = False
Cl2 = IIf(Lb1.ListIndex < 1, 2, Lb1.ListIndex + 2)
OpenLb2 Cl2, ActiveCell
ElseIf KeyCode = 28 Then
Lb1.Visible = False
End If
End Sub
'--------------------------------------------
Private Sub Lb2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Nhap
End Sub
'-----------------------------------------------
Private Sub Lb2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Nhap
ElseIf KeyCode = 28 Then
Lb2.Visible = False
ActiveCell.Select
End If
End Sub
'----------------------------------------
Sub Nhap()
On Error GoTo Thoat
If Lb2.ListIndex = "" Then Lb2.ListIndex = 0
If ActiveCell.Column = 3 Then
ActiveCell = Lb2
ActiveCell.Offset(, 1) = Lb2.Column(1)
ActiveCell.Offset(, 2) = Lb2.Column(2)
Else
ActiveCell = Lb2
End If
Lb2.Visible = False
ActiveCell.Select
Thoat:
End Sub
'----------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target
If .Row > 9 And .Column = 7 And .Cells.Count = 1 Then
OpenLb2 1, ActiveCell
ElseIf .Row > 9 And .Column = 3 And .Cells.Count = 1 Then
Lb1.Top = .Top
Lb1.Left = .Left
Lb1.Visible = True
Lb1.ListFillRange = Sheet2.Name & "!" & Sheet2.Range(Sheet2.[AO2], Sheet2.[AO1000].End(xlUp)).Address
Lb1.Activate
Else
Lb1.Visible = False
Lb2.Visible = False
End If
End With
End Sub