Hello as many others I'm new in VBA. I have the following code. It run well as must be, except for lats row if i debug the code until last 2 rows the system said I have a string in strCWidths which is the width of the columns inside of the Listbox, but as soon I hit F8 to continue the .ColumnWidths lost the decimal and convert averting as complete number, no decimal.
In other words, if in strCWidths i have "12.5;13.5;10.2", after hit F8 I have "125;135;102" in .ColumnWidths
I already change the decimal symbol in the control panel, region. and it only works if I don't close excel.
What is set up the width columns dynamically
Private Sub CmbCodigo_Change()
Application.ScreenUpdating = False
Dim colradio As Single
Dim strCWidths As String
Me.LixbCodigo.Clear
Sheets("General").Select
criteria = Me.CmbCodigo
lr = ThisWorkbook.Sheets("General").Cells(Rows.Count, "A").End(xlUp).Row
With Me.LixbCodigo
Me.LixbCodigo.ColumnCount = 3
.ColumnWidths = ""
For i = 2 To lr
If Cells(i, "D") = criteria Then
.AddItem Cells(i, "D")
.List(.ListCount - 1, 1) = Cells(i, "E")
.List(.ListCount - 1, 2) = Cells(i, "F")
' .List(.ListCount - 1, 3) = Cells(i, "G")
End If
Next i
For i = 1 To .ColumnCount
With Me.Controls.Add("Forms.TextBox.1", Name:="txtTemp" & i)
.AutoSize = True
.MultiLine = True
.WordWrap = False
.SelectionMargin = True
With .Font
.Name = LixbCodigo.Font.Name
.Size = LixbCodigo.Font.Size
End With
End With
Next i
For i = 0 To .ListCount - 1
Me.Controls("txtTemp1").Text = Me.Controls("txtTemp1").Text & vbCr & .List(i, 0)
Me.Controls("txtTemp2").Text = Me.Controls("txtTemp2").Text & vbCr & .List(i, 1)
Me.Controls("txtTemp3").Text = Me.Controls("txtTemp3").Text & vbCr & .List(i, 2)
Next i
colradio = 0.1557
For i = 1 To .ColumnCount
strCWidths = strCWidths & Me.Controls("txtTemp" & i).Width & ";"
lngTotalWidth = lngTotalWidth + Me.Controls("txtTemp" & i).Width
Me.Controls("txtTemp" & i).Visible = False
Me.Controls.Remove ("txtTemp" & i)
Next i
.Width = lngTotalWidth + LixbCodigo.ColumnCount + 10
.ColumnWidths = strCWidths
End With
Application.ScreenUpdating = True
End Sub
Bookmarks