Newbie Treeview Remove Nodes Question
In my treeview, I'm trying to loop through and remove all the nodes that don't have children. I found some code which seemed to work for the folks on the thread, but I can't get it to work with mine. It keeps stopping on the Remove line, saying "Invalid Key." I've found a couple of explanations with other scenarios for the "Invalid key" message but I'm too much of a newb to fix it as it relates to what I'm trying to do. Can anyone explain it in a little detail what I need to do to fix it? :blush:
Here is the code:
Code:
Dim x As Node, y() As Node: ReDim y(0)
For Each x In Tree1.Nodes
If x.Child Is Nothing Then
Set y(UBound(y)) = x
ReDim Preserve y(UBound(y) + 1)
End If
Next
Dim i As Long
For i = 0 To UBound(y) - 1
Tree1.Nodes.Remove y
Next
Thanks :)
EDIT: Thanks Bruce :bigyello: