ListBox.ColumnWidth does not work

drom

Well-known Member
Joined
Mar 20, 2005
Messages
543
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and Thanks in advane!

I have a ListoBox from the "ActiveX Controls" attached to the range: range("D2:E4")

The listFillRange of this ListBox is a dinamic range with 4 columns, "columns are always 4" rows is dinamic.

in this ListBox I am showing the 2nd and the 4th Column of my dinamic range named "rPT"

so ColumnCount = 4

now I would like to fix the ColumnWidths.
At present I have got this done this way:
ColumnWidths=0 pt;75 pt;0 pt;175 pt


I would like to do this by VBA and my code works fine but the ListBox does not apply the changes to the Width...


I mean If I do:
Code:
Private Sub ListBox1_Click()
Dim rPT As Range: Set rPT = Range("$C$5:$D$5")
Dim xx As Long:   xx = rPT.Cells(1).Width
Dim yy As Long:   yy = rPT.Cells(2).Width
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths =  "0;" & xx & ";0;" & yy
End Sub

I can see on the ListBox properties that the columnsWidth are OK, but the listBox does not apply those changes to the ListBox, I know this because if I change manually the Columns("C:C") width to 200 and then I click on the listBox, the ListBox still equal.
But the debug.print ListBox1.ColumnWidths CHANGES
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Put your code in the ListBox1_GotFocus event instead.
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top