Hi
In the folloing code I am populating a multiselect listbox "LBox_Varied" based on a passed Range object "MyRange". This runs when the User form in opened.
At the end of the code I am trying to resize the listbox to fit the number of records.
----.Height = .ListCount * RowHeight----
My problem is that the form will not normally repaint, but if I include a msgbox command (commented out in the attached) it does repaint.
Any ideas?
Thanks
Declan
VB Code:
Private Sub UserForm_Initialize() Dim DimName As String Dim RowHeight As Integer DimName = MyRange.Worksheet.Name DimName = Right(DimName, Len(DimName) - 1) DimName = Replace(DimName, "_", " ") Me.Caption = "Select " & DimName RowHeight = 14 With Me.LBox_Varied .List = MyRange.Value For MyItem = 1 To .ListCount .Selected(MyItem - 1) = .List(MyItem - 1, 1) Next MyItem .Height = .ListCount * RowHeight End With Me.Repaint 'msgbox "anything" End Sub




Reply With Quote