VBA Help - Cycle through reporting hierarchy to find FIRST MATCH

Nexus981

New Member
Joined
Sep 20, 2017
Messages
7
Hi,

I am working with a old macro written by someone no longer around (and secondly its not working consistently)

I have a reporting Hierarchy that looks like this
18615
,38630,29199,22163,26079,14516,16114,10614

<tbody>
</tbody>
I removed the commas and have each ID in its own cell going from Left to right.

I have a separate list of IDS where I would like the matching to stop once it finds the FIRST match. I.E. I want to stop when I find an employee that is the FIRST VP in this person's hierarchy.

18615
,38630,29199,22163,26079,14516,16114,10614

<tbody>
</tbody>
n/a n/a n/a YES

From there I will look for this ID and bring back the details (I think I can handle that part of the code)

I need to run through this process roughly 3,000+ times
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
... more detail

See bellow ... I would have 3K+ rows of data that look like the below
emp_idemp_id_chainLevel 1Level 2Level 3Level 4Level 5Level 6Level 7Level 8
18615,38630,29199,22163,26079,14516,16114,1061438630291992216326079145161611410614
36627,39982,30821,12573,12060,17853,16114,1061439982308211257312060178531611410614
5495,4194,4196,4582,4581,16114,1061441944196458245811611410614

<tbody>
</tbody><colgroup><col><col><col><col span="7"></colgroup>
 
Upvote 0
Nexus981,

Welcome to the Board.

Code:
I want to stop when I find an employee that is the FIRST VP in this person's hierarchy.

Given your range of id numbers, how are we to determine which is a VP? (Maybe you have a separate table or list of vp id's? On the same sheet? In what range?)

Once found, how do you want the results displayed? Highlighted? Added to another column? (Which column?)

Cheers,

tonyyy
 
Last edited:
Upvote 0
Tonny,

1. I have the list of VPs on a different excel tab
2. As far as output goes, I would place the resulting FIRST MATCH next to the unique EMP_ID ( i.e. column 11, row X)


FIND FIRST MATCH -> Look up said match -> Return Results ( I would be bringing in other values like the name ,locations etc. ALL based of FIRST MATCH)

Thanks for your help so far.
 
Upvote 0
You might consider the following...

Code:
Sub FirstMatch_1023533()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim arr1 As Variant, arr2 As Variant, arr3 As Variant
Dim r As Long, c As Long, i As Long

Set ws1 = Sheets("Sheet1") 'employee list
Set ws2 = Sheets("Sheet2") 'vp list

arr1 = ws1.Range(ws1.Cells(2, 1), ws1.Cells(ws1.Cells(Rows.Count, 1).End(xlUp).Row, 10)) 'emp array
arr2 = ws2.Range(ws2.Cells(1, 1), ws2.Cells(ws2.Cells(Rows.Count, 1).End(xlUp).Row, 1)) 'vp array
ReDim arr3(1 To Cells(Rows.Count, 1).End(xlUp).Row - 1, 1 To 1) 'results array

For r = 1 To UBound(arr1, 1)
    For c = 3 To UBound(arr1, 2)
        For i = 1 To UBound(arr2, 1)
            If arr1(r, c) = arr2(i, 1) Then
                arr3(r, 1) = arr2(i, 1)
                GoTo Nexxt
            End If
        Next i
    Next c
Nexxt:
Next r

ws1.Range("K2:K" & ws1.Cells(Rows.Count, 1).End(xlUp).Row).Value = arr3
End Sub

Assumptions:

The employee list is on "Sheet1"
The vp id numbers are on "Sheet2" in Column A
 
Last edited:
Upvote 0
I will check this out. Thanks for all the help. I need to get better at this stuff. While I was waiting I banged it out in excel with embedded If error statements. It got the job done, but I need to get better at VBA, so powerful.
 
Upvote 0
You're welcome. Glad you have a solution...
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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