KennyExcel
New Member
- Joined
- Jan 22, 2016
- Messages
- 5
Hi all,
Going absolutely nuts trying to resolve this so was hoping somebody out there could show me the way. So I am trying to create a tree view within a userform and received some code from a friend but anytime I try to run this I receive the error as stated in the subject line. The piece of code it then highlights is ".tvList". Any help would be greatly appreciated. I have included my code below and highlighted the offending line:
Option Explicit
Private Sub cmdALL_Click()
Dim nd As Node
For Each nd In Me.tvList.Nodes
nd.Checked = True
Next nd
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not select all items"
Resume exitHandler
End Sub
Private Sub cmdClear_Click()
Dim nd As Node
For Each nd In Me.tvList.Nodes
nd.Checked = False
Next nd
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not clear all items"
Resume exitHandler
End Sub
Private Sub cmdClose_Click()
Unload Me
'move down one row
ActiveCell.Offset(0, 1).Activate
End Sub
Private Sub cmdOK_Click()
Dim nd As Node
Dim strSel As String
strSel = ""
For Each nd In Me.tvList.Nodes
If Left(nd.Key, 5) = "Child" Then
If nd.Checked = True Then
strSel = strSel & nd.Text & strSep
End If
End If
Next nd
If Len(strSel) > 0 Then
strSel = Left(strSel, Len(strSel) - Len(strSep))
ActiveCell.Value = strSel
Else
MsgBox "No selections"
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim rngMth As Range
Dim rngMD As Range
Dim cM As Range
Dim cMD As Range
Dim lParent As Long
Dim lChild As Long
Dim strParent As String
Set wb = ThisWorkbook
Set rngMth = wb.Names(strDVList).RefersToRange
lParent = 1
lChild = 1
With Me.tvList.Nodes
.Clear
For Each cM In rngMth
strParent = "Parent" & Format(lParent, "000")
If cM.Value <> cM.Offset(-1, 0).Value Then
.Add Key:=strParent, _
Text:=cM.Value
lParent = lParent + 1
.Add Relative:=strParent, _
Relationship:=tvwChild, _
Key:="Child" & Format(lChild, "000"), _
Text:=cM.Offset(0, 1).Value
lChild = lChild + 1
Else
strParent = "Parent" & Format(lParent - 1, "000")
.Add Relative:=strParent, _
Relationship:=tvwChild, _
Key:="Child" & Format(lChild, "000"), _
Text:=cM.Offset(0, 1).Value
lChild = lChild + 1
End If
Next cM
End With
End Sub
Going absolutely nuts trying to resolve this so was hoping somebody out there could show me the way. So I am trying to create a tree view within a userform and received some code from a friend but anytime I try to run this I receive the error as stated in the subject line. The piece of code it then highlights is ".tvList". Any help would be greatly appreciated. I have included my code below and highlighted the offending line:
Option Explicit
Private Sub cmdALL_Click()
Dim nd As Node
For Each nd In Me.tvList.Nodes
nd.Checked = True
Next nd
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not select all items"
Resume exitHandler
End Sub
Private Sub cmdClear_Click()
Dim nd As Node
For Each nd In Me.tvList.Nodes
nd.Checked = False
Next nd
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not clear all items"
Resume exitHandler
End Sub
Private Sub cmdClose_Click()
Unload Me
'move down one row
ActiveCell.Offset(0, 1).Activate
End Sub
Private Sub cmdOK_Click()
Dim nd As Node
Dim strSel As String
strSel = ""
For Each nd In Me.tvList.Nodes
If Left(nd.Key, 5) = "Child" Then
If nd.Checked = True Then
strSel = strSel & nd.Text & strSep
End If
End If
Next nd
If Len(strSel) > 0 Then
strSel = Left(strSel, Len(strSel) - Len(strSep))
ActiveCell.Value = strSel
Else
MsgBox "No selections"
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim rngMth As Range
Dim rngMD As Range
Dim cM As Range
Dim cMD As Range
Dim lParent As Long
Dim lChild As Long
Dim strParent As String
Set wb = ThisWorkbook
Set rngMth = wb.Names(strDVList).RefersToRange
lParent = 1
lChild = 1
With Me.tvList.Nodes
.Clear
For Each cM In rngMth
strParent = "Parent" & Format(lParent, "000")
If cM.Value <> cM.Offset(-1, 0).Value Then
.Add Key:=strParent, _
Text:=cM.Value
lParent = lParent + 1
.Add Relative:=strParent, _
Relationship:=tvwChild, _
Key:="Child" & Format(lChild, "000"), _
Text:=cM.Offset(0, 1).Value
lChild = lChild + 1
Else
strParent = "Parent" & Format(lParent - 1, "000")
.Add Relative:=strParent, _
Relationship:=tvwChild, _
Key:="Child" & Format(lChild, "000"), _
Text:=cM.Offset(0, 1).Value
lChild = lChild + 1
End If
Next cM
End With
End Sub