How to set "top" of listbox

G

Guest

I am having a problem setting the height of a listbox.

I have a userform with a listbox containing all range names of the workbook.
Below this listbox are two command buttons. I want to show all range names
(usually a number between 3 and 6), so I set the height of the listbox, then
set the "Top" of the two command buttons, and then set the height of the
userform.

The following code is in the Initialize event of the userform:
ListBox1.Height = Count * 12 + 2
cmdPrint.Top = 96 + ListBox1.Height + 16
cmdClose.Top = 96 + ListBox1.Height + 16
uflPrtRng.Height = 96 + ListBox1.Height + 16 + cmdClose.Height + 16 + 20

This sets the top of the buttons to be 16 points below the bottom of the
listbox. (At least that's what I was hoping it would do!)

The trouble is that the first line seems to be ignored! If Count = 6 then
the height should be 74. I'll run the code and the height is 49.2!! Then
I'll step thru the code and the height is set to 74 and the form looks good.
I'll run the code again without stepping thru it and it's back to 49.2.

The listbox is not locked and it's initial height in design mode is 50.

Is there some other property that I don't have set correctly??

Thank You!
 
G

Gary Keramidas

i do something similar to show a form depending on the number of items will
populate the list box.

i have my code in the userform.activate section.

i use a case statement to determine the value of z

With UserForm2
.Caption = ws.Range("F" & i).Value & " [" & _
ws.Range("E" & i).Value & "]"
.Width = 280 + z + 65
.Height = 63 + (z * 18)
.ListBox1.Height = 5 + z * 12
.ListBox1.Width = 170
.ListBox1.Left = 20
'.ListBox1.Enabled = False
.ListBox2.Height = 5 + z * 12
.ListBox2.Width = 60
.ListBox2.Left = 190
.ListBox3.Left = 250
.ListBox3.Width = 60
.ListBox3.Height = 5 + z * 12
.ListBox1.SetFocus
.Label1.Left = 10
.Label2.Left = 190
.Label3.Left = 250
.TextBox1.Top = 30 + z * 12
.TextBox1.Left = 190
.TextBox1.Width = 60
.TextBox1.Value = Format(totPounds, "#,###.00")
.TextBox2.Top = 30 + z * 12
.TextBox2.Left = 250
.TextBox2.Width = 60
.TextBox2.Value = Format(BatPounds, "#,###.00")
.TextBox3.Top = 30 + z * 12
.TextBox3.Left = 170
.TextBox3.Width = 20
.TextBox3.Value = z
.CommandButton1.Top = 30 + z * 12
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top