K
ker_01
I am working with an org chart "tree" in table form to find the reporting
heirachy. I start with the employee name, look it up on another table, and
find that person's reporting manager. Then I look up that manager as an
employee to find their manager, and so on.
Eventually each tree hits an error when I get to the top of the tree,
because it can't find a matching manager name. So, I use onError to escape
the loop and present the data onscreen for review.
This works fine the first time, but the code stops with an error on the
second 'original' employee- it is like the code forgot about the OnError
statement. I even added a goto 0 statement in case it needs some type of
'reset', but that didn't help.
Any ideas?
Thanks,
Keith
sorry for the linewrap...
Sub CheckHRSTCNames()
Dim OutArr(1 To 10)
SHRRowCnt = lastRow(Sheets(7))
SourceHRIDArr = Sheets(7).Range("A1:A" & SHRRowCnt)
SourceHRMgrArr = Sheets(7).Range("B1:B" & SHRRowCnt)
For tempRow = 2 To lastRow(Sheets(6))
Erase OutArr
tID = Sheets(6).Range("A" & tempRow).Value
matchRow = Application.Match(CStr(tID), SourceHRIDArr, False)
'Debug.Print tID
On Error GoTo ShowResults
For p = 1 To 10
OutArr(p) = Sheets(7).Range("AD" & matchRow).Value '<--errors here
on second loop, when p gets to about 7 or 8 depending on the employee
matchRow = Application.Match(OutArr(p), SourceHRMgrArr, False)
Next
ShowResults:
MsgBox OutArr(1) & ", " & OutArr(2) & ", " & OutArr(3) & ", " &
OutArr(4) & ", " & OutArr(5) & ", " & _
OutArr(6) & ", " & OutArr(7) & ", " & OutArr(8) & ", " &
OutArr(9) & ", " & OutArr(10)
On Error GoTo 0
Next
End Sub
heirachy. I start with the employee name, look it up on another table, and
find that person's reporting manager. Then I look up that manager as an
employee to find their manager, and so on.
Eventually each tree hits an error when I get to the top of the tree,
because it can't find a matching manager name. So, I use onError to escape
the loop and present the data onscreen for review.
This works fine the first time, but the code stops with an error on the
second 'original' employee- it is like the code forgot about the OnError
statement. I even added a goto 0 statement in case it needs some type of
'reset', but that didn't help.
Any ideas?
Thanks,
Keith
sorry for the linewrap...
Sub CheckHRSTCNames()
Dim OutArr(1 To 10)
SHRRowCnt = lastRow(Sheets(7))
SourceHRIDArr = Sheets(7).Range("A1:A" & SHRRowCnt)
SourceHRMgrArr = Sheets(7).Range("B1:B" & SHRRowCnt)
For tempRow = 2 To lastRow(Sheets(6))
Erase OutArr
tID = Sheets(6).Range("A" & tempRow).Value
matchRow = Application.Match(CStr(tID), SourceHRIDArr, False)
'Debug.Print tID
On Error GoTo ShowResults
For p = 1 To 10
OutArr(p) = Sheets(7).Range("AD" & matchRow).Value '<--errors here
on second loop, when p gets to about 7 or 8 depending on the employee
matchRow = Application.Match(OutArr(p), SourceHRMgrArr, False)
Next
ShowResults:
MsgBox OutArr(1) & ", " & OutArr(2) & ", " & OutArr(3) & ", " &
OutArr(4) & ", " & OutArr(5) & ", " & _
OutArr(6) & ", " & OutArr(7) & ", " & OutArr(8) & ", " &
OutArr(9) & ", " & OutArr(10)
On Error GoTo 0
Next
End Sub