View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
pano[_4_] pano[_4_] is offline
external usenet poster
 
Posts: 5
Default Listbox how to get to appear left of cell?

My thanks to RORYA for the solution

This version will put it on the right if it will fit, the left if not:

Code:


Option Explicit
Private Sub CheckBox1_Click()
ListBox1.Visible = CheckBox1.Value
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

With ListBox1
.Width = 250
.Height = 200

' offset listbox to the left
L = ActiveCell.Left - .Width
' if the listbox would go off screen, then move it to the right
If L < 0 Then L = ActiveCell.Left + ActiveCell.Width
T = ActiveCell.Top

' position listbox
.Top = T
.Left = L
End With
End Sub__________________
Regards,
Rory

Give someone a program, and you frustrate them for a day;
teach someone to program, and you frustrate them forever.