TreeView Help

Swordsman

New Member
Joined
Mar 10, 2022
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Can i get some help at my userform .
i try to add new Node child for the excite Node child .
as you can see at the attached form i have main parent witch is column" H " and the child is column "B".
i want to move column B and insert new column so column "B" will be the main child and column "C" add new child for the tree view .
Wish I could explain what i need :(
this the code i'm using


Sub treeview_load_data()
Dim cFilterRange As Excel.Range
Dim c As Range
Dim nParent As Node
Dim nChild As Node
Dim ws As Worksheet

On Error GoTo ErrHandler

Application.ScreenUpdating = False

tv.Nodes.Clear
tv.Top = 24
Set ws = Sheet1

With ws

'// Clear any set filters
'// AutoFilters
.AutoFilterMode = False
If .FilterMode Then .ShowAllData

'// Create the filtered range for Column A
Set cFilterRange = .Range("I1:I" & Sheet1.Range("I" & Rows.Count).End(xlUp).Row)
'// Apply a unique filter to Col A
cFilterRange.AdvancedFilter Action:=xlFilterInPlace, Unique:=True

'// Now add only those visible rows - Using Col A here
For Each c In cFilterRange.SpecialCells(xlCellTypeVisible)

If c.Row <> 1 Then

tv.Nodes.Add , , c.Value, c.Value
End If
Next
.ShowAllData
Set cFilterRange = Nothing
Set cFilterRange = .Range("B1:B" & Sheet1.Range("I" & Rows.Count).End(xlUp).Row)
cFilterRange.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
For Each c In cFilterRange.SpecialCells(xlCellTypeVisible)
If c.Row <> 1 Then

Set nParent = tv.Nodes(c.Offset(0, 7).Value)
tv.Nodes.Add nParent, tvwChild, c.Value, c.Value
End If
Next
End With
ErrHandler:
tv.Top = 24
Application.ScreenUpdating = True

tv.Top = 24
End Sub
 

Attachments

  • 1.jpg
    1.jpg
    150 KB · Views: 17

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Not sure if it's this simple but if you want a new column B:

Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

The above selects Column B and Selection.Insert will insert a new Column B and the old Column B becomes Column C.
If this isn't the solution you are looking for, maybe upload a 2nd picture, that shows Before and After with data and I will take another look at it.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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