• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Column widths in Listbox on userform.

IPBR21054

New Member
My code below that I’m currently using doesn’t allow me to have / adjust column widths.
Sometimes the value in my listbox is cut off because of this.
Please can you advise me a code so I can adjust columns widths to suit where at present I have no control.

Thanks.

>>> use code - tags <<<
Code:
Private Sub UserForm_Activate()
  Dim dic1 As Object, dic2 As Object, dic3 As Object
  Dim i As Long
  Set dic1 = CreateObject("Scripting.Dictionary")
  Set dic2 = CreateObject("Scripting.Dictionary")
  Set dic3 = CreateObject("Scripting.Dictionary")
 
  a = Range("A1:G" & Range("D" & Rows.Count).End(3).Row).Value
  ListBox1.ColumnCount = 7
 
'first column D second column F & third column G
  For i = 2 To UBound(a, 1)
    dic1(Range("D" & i).Value) = Empty
    dic2(Range("F" & i).Value) = Empty
    dic3(Range("G" & i).Value) = Empty
  Next
 
  ComboBox1.List = dic1.keys
  ComboBox2.List = dic2.keys
  ComboBox3.List = dic3.keys
End Sub
 
Last edited by a moderator:
As you can directly set the columns widths in the ComboBox Properties window on VBE side …​
If you really need to program a VBA procedure for that - better with the Initialize event rather than Activate - then​
use the VBA property ListBox.ColumnWidths as explained in VBA help.​
 
Back
Top