abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,503
- Office Version
- 2019
- 2010
- Platform
- Windows
Hi guys
I have code to search on userform but my problem I cant arrange columns width in listbox some columns are stuck each other and some columns are big space between each other
I don't want tradition way as known like this
.ColumnWidths = "80;80;120;80;60;60;60;60;60;60"
I want the ColumnWidths as the same thing inside the sheet to avoid problem unarranged columns in listbox
here is part of my project
thanks
I have code to search on userform but my problem I cant arrange columns width in listbox some columns are stuck each other and some columns are big space between each other
I don't want tradition way as known like this
.ColumnWidths = "80;80;120;80;60;60;60;60;60;60"
I want the ColumnWidths as the same thing inside the sheet to avoid problem unarranged columns in listbox
here is part of my project
VBA Code:
Private Sub LBoxPop()
Dim i&, j&, x&
Dim myFormat(1) As String, crit As String
Dim cmb2 As Long
If ComboBox1.ListIndex = -1 Then Exit Sub
Set WS = Sheets(ComboBox1.Value)
Data = WS.Cells(1).CurrentRegion.Value
myFormat(0) = WS.Cells(2, 8).NumberFormatLocal
myFormat(1) = WS.Cells(2, 9).NumberFormatLocal
ReDim Temp(1 To UBound(Data, 1), 1 To 10)
x = 1
For j = 1 To 10
Temp(x, j) = Data(x, j)
Next
For i = 2 To UBound(Data)
If TextBox1.Value = "" Then crit = Data(i, 4) Else crit = TextBox1.Value
If ComboBox2.Value = "" Then cmb2 = Month(Data(i, 2)) Else cmb2 = Val(ComboBox2.Value)
If Data(i, 4) Like crit & "*" And Month(Data(i, 2)) = cmb2 Then
x = x + 1
For j = 1 To 10
Temp(x, j) = Data(i, j)
If j = 2 Then Temp(x, 2) = Format(Data(i, 2), "DD/MM/YYYY")
If j >= 8 Then Temp(x, j) = Format$(Data(i, j), myFormat(1))
Next j
End If
Next i
With UserForm1.ListBox1
.Clear
.ColumnCount = 10
.ColumnWidths = "80;80;120;80;60;60;60;60;60;60"
.List = Temp
End With
End Sub