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:
  1. Private Sub UserForm_Initialize()
  2.     Dim DimName As String
  3.     Dim RowHeight As Integer
  4.    
  5.     DimName = MyRange.Worksheet.Name
  6.     DimName = Right(DimName, Len(DimName) - 1)
  7.     DimName = Replace(DimName, "_", " ")
  8.     Me.Caption = "Select " & DimName
  9.    
  10.     RowHeight = 14
  11.    
  12.     With Me.LBox_Varied
  13.         .List = MyRange.Value
  14.            
  15.         For MyItem = 1 To .ListCount
  16.             .Selected(MyItem - 1) = .List(MyItem - 1, 1)
  17.         Next MyItem
  18.        
  19.         .Height = .ListCount * RowHeight
  20.        
  21.     End With
  22.    
  23.     Me.Repaint
  24.     'msgbox "anything"
  25. End Sub