Hello All,
I have a multicolumn listbox that is populated with elements that are in the parent -> child -> grandchild format. The elements labels are as follows:
The listbox is populated by RowSource. I would like to indent each item in the listbox according to its position in the hierarchy. Similar to the following:
My code for performing the indent process is as follows:
I'm having trouble applying the Additem property to the multicolumn listbox. Essentially what I want to do is reference an item in a listbox, edit it by adding some spaces to it, and then plug it back in to the same position in the listbox.
Any suggestions would be greatly appreciated.
I have a multicolumn listbox that is populated with elements that are in the parent -> child -> grandchild format. The elements labels are as follows:
Code:
01 - Text
01.01 - Text
01.01.01 - Text
01.01.02 - Text
Code:
01 - Text
01.01 - Text
01.01.01 - Text
01.01.02 - Text
Code:
Sub ListBox_Indent()
Dim i As Long
Dim j As Long
Dim c As String
Dim r As Long
Dim s As Long
Dim ind As String
With UserForm1.ListBox1
For i = 0 To .ListCount - 1
c = .Column(2, i)
r = Len(c)
s = Len(WorksheetFunction.Substitute(c, ".", ""))
If (r - s) = 0 Then
'do nothing
Else
ind = String((r - s), " ")
c = ind & c
.Column(2, i) = c '<--Error Here
End If
Next i
End With
End Sub
Any suggestions would be greatly appreciated.