Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Listbox how to get to appear left of cell?

Hi all, I have the following code, a checkbox and listbox on a sheet
at the moment the list box appears to the right of the column , I
want it to appear to the left of the data entry column.

Can someone help me on what to change here, I have tried the
properties on the list box itself but it just resets, I reckon this
code controls the size,shape,location of the list box.

Thanks for the help


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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i no margin string in listbox from left tom taol Excel Programming 0 April 23rd 08 05:58 AM
align left and right in listbox Dennis Excel Programming 2 September 14th 07 03:14 PM
How to make a cell appear in upper left (top left) corner of works jeff Excel Programming 2 March 6th 07 10:14 PM
How to add picture to the left corner of listbox index [email protected] Excel Programming 1 July 26th 06 06:49 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 01:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"