View Single Post
  #17   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default ComboBox listwidth to match text in list

That is what I am talking about as well, however, the text originated on a
worksheet. If not, then it is trivial to put it on a scratch sheet and use
this method but that may may not seem elegant and whatever method you are
pursuing may be more preferred.

Assuming a single column Combobox o rlistbox (listbox here)
v = Me.ListBox1.List
For i = LBound(v) To UBound(v)
If Len(v(i, LBound(v, 2))) maxlen Then
maxlen = Len(v(i, LBound(v, 2)))
End If
Next
MsgBox maxlen

will get your maxlen in terms of characters if that is what you were asking.

--
Regards,
Tom Ogilvy



"J.S.Winstrom" wrote:

?B?VG9tIE9naWx2eQ==?= wrote
in on Fri 03 Aug
2007 09:24:02a:

Here is what I mean Jim.

Private Sub UserForm_Initialize()
With Worksheets("Sheet1").Columns(6)
c = .ColumnWidth
.WrapText = False
.AutoFit
Me.ListBox1.ColumnWidths = .Width + 10
Me.ListBox1.Width = .Width + 20
Me.ListBox1.Font.Name = _
.Parent.Range("F10").Font.Name
Me.ListBox1.Font.Size = _
.Parent.Range("F10").Font.Size
.ColumnWidth = c
DoEvents
End With
End Sub

It worked perfectly for me. The OP would have to address restoring
wraptext to the Column IN THE WORKSHEET if that were a problem.

But I see you have led him on a merry dance, so hopefully he is happy.



For the most part, I'm headed in the right direction. I just need to
figure out how to load the array with the widths of the text entries and
the compare them to each other to find which one is the largest. Once I
can hack that data apart, I'll have what I need. But for the record, I
wasn't talking about a cell on a worksheet like you referenced in your
example. I was refering to a combobox list on a userform. So maybe that
line could be altered to say something to reference Combobox.Font.Size?

Anyways, thanks again guys for the help.

~J.S.Winstrom