giaosy
Thành viên thường trực
- Tham gia
- 6/12/06
- Bài viết
- 205
- Được thích
- 144
Option Explicit
Private Sub CheckBox1_Click()
If CheckBox1 Then
ListBox1.Visible = True
Else
ListBox1.Visible = False
End If
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim Target As Range
Dim MySel As Range
Set Target = Range("VBA_Target")
Set MySel = Intersect(ActiveCell.EntireRow, Target)
MySel.Value = ListBox1.Value
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim L As Double
Dim T As Double
Dim MaxR As Double
Dim MaxB As Double
Dim n As Integer
Dim ListR As Double
Dim ListB As Double
ListBox1.Width = 250
ListBox1.Height = 200
MaxR = Cells(1, 256).Left + Cells(1, 256).Width
MaxB = Cells(65536, 1).Top + Cells(65536, 1).Height
If ActiveCell.Column >= 255 Then
n = 0
Else
n = 2
End If
L = ActiveCell.Offset(0, n).Left
T = ActiveCell.Top
ListR = L + ListBox1.Width
ListB = T + ListBox1.Height
If ListR >= MaxR Then
L = MaxR - ListBox1.Width - (MaxR - ActiveCell.Offset(0, -1).Left)
End If
If ListB >= MaxB Then
T = MaxB - ListBox1.Height
End If
ListBox1.Top = T
ListBox1.Left = L
End Sub
Private Sub CheckBox1_Click()
If CheckBox1 Then
ListBox1.Visible = True
Else
ListBox1.Visible = False
End If
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim Target As Range
Dim MySel As Range
Set Target = Range("VBA_Target")
Set MySel = Intersect(ActiveCell.EntireRow, Target)
MySel.Value = ListBox1.Value
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim L As Double
Dim T As Double
Dim MaxR As Double
Dim MaxB As Double
Dim n As Integer
Dim ListR As Double
Dim ListB As Double
ListBox1.Width = 250
ListBox1.Height = 200
MaxR = Cells(1, 256).Left + Cells(1, 256).Width
MaxB = Cells(65536, 1).Top + Cells(65536, 1).Height
If ActiveCell.Column >= 255 Then
n = 0
Else
n = 2
End If
L = ActiveCell.Offset(0, n).Left
T = ActiveCell.Top
ListR = L + ListBox1.Width
ListB = T + ListBox1.Height
If ListR >= MaxR Then
L = MaxR - ListBox1.Width - (MaxR - ActiveCell.Offset(0, -1).Left)
End If
If ListB >= MaxB Then
T = MaxB - ListBox1.Height
End If
ListBox1.Top = T
ListBox1.Left = L
End Sub