Home » excel » excel – I have a problem with combobox when showing scroll

excel – I have a problem with combobox when showing scroll

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have a problem with combobox for showing content.
When I scroll some of the content, like in the attached picture, it is hidden.

enter image description here

My combobox text alignment is to the right

How to&Answers:

Taken from this source you can put this code in your UserForm.Initialize procedure, e.g.:

Private Sub UserForm_Initialize()

Dim I As Long, TempString As String
UserForm1.ComboBox1.ColumnCount = 2
TempString = LTrim$(Str$(UserForm1.ComboBox1.Width - 15))
UserForm1.ComboBox1.ColumnWidths = TempString & " pt; 15 pt"
For I = 1 To 10
    UserForm1.ComboBox1.AddItem "Hello" & Str$(I)
Next I

End Sub

enter image description here

Another option that works for me is:

Private Sub UserForm_Initialize()

Dim I As Long
For I = 1 To 10
    UserForm1.ComboBox1.AddItem "Hello " & I & "     "
Next I

End Sub

This last option would just put enough trailing spaces to let the text appear fully. Note that when you use those values you will have to TRIM them down.