On a form i'm creating I'm attempting to set the height of a listbox based upon the number of items entered into the listbox. The listbox is added dynamically at runtime via code and is called ListAdd. I have a variable called ListHeight which contains the total height needed for the listbox. Here's my code:
The strange thing is that the listbox height will not set correctly, however when I inserted the msgbox line to check the values it worked. The height is always set correctly when the msgbox is displayed and it never works if the msgbox isn't displayed. Could this be a waiting issue? But that doesn't make sense because the msgbox line is after the height change code.
Anybody see something wrong in my code? Or does someone know a better way of changing a listbox height based on te number of entries?
Thanks!
BD
Code:
ListAdd.RowSource = ThisWorkbook.Sheets("Project_Info").Range(Cells(2, 11), Cells(ListCount + 1, 15)).Address
ListAdd.Height = ListHeight
'MsgBox "ListAdd.Height = " & ListAdd.Height & vbLf & "ListHeight = " & ListHeight
The strange thing is that the listbox height will not set correctly, however when I inserted the msgbox line to check the values it worked. The height is always set correctly when the msgbox is displayed and it never works if the msgbox isn't displayed. Could this be a waiting issue? But that doesn't make sense because the msgbox line is after the height change code.
Anybody see something wrong in my code? Or does someone know a better way of changing a listbox height based on te number of entries?
Thanks!
BD