0
votes

I have a scenario where employee data is given in excel sheet with his supervisors details (name and email id). And a supervisor is himself an employee so he will have his supervisors details(name and email id) and so on...

In tabular format -

emp_name email_id supervisor1_name supervisor1_emailid
abc      abc@xyz.com    pqr           pqr@xyz.com
--------------------------------------
--------------------------------------
pqr      pqr@xyz.com    lmn           lmn@xyz.com

I want to show the above data in the excel sheet itself as follows,

emp_name email_id supervisor1_name supervisor1_emailid  supervisor2_name suprvisor2_emailid
abc      abc@xyz.com    pqr           pqr@xyz.com         lmn           lmn@xyz.com

and so on the supervisor details........

till the last supervisor details for each employee.

I am not aware about vba or macros in excel.
I can do it by using vlookup function in excel but its taking too much time so I want to do it by quick and faster way programmatically.

1

1 Answers

0
votes

Perhaps this will hep you get started.

Dim FirstRow As Integer
Dim EndRow As Integer
FirstRow = 2
EndRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 2).End(xlUp).row

Dim supName As String
Dim secRow As Long

For row = FirstRow To EndRow
    supName = Range("C" & row)
    If supName <> "" Then
        Do Until supName = ""
            For secRow = FirstRow To EndRow
                If Range("A" & secRow) = supName Then
                    Cells(row, Cells(row, Sheets(1).Columns.Count).End(-4159).Column + 1) = Range("C" & secRow)
                    Cells(row, Cells(row, Sheets(1).Columns.Count).End(-4159).Column + 1) = Range("D" & secRow)
                    supName = Range("C" & secRow)
                    Exit For
                End If
            Next secRow
        Loop
    End If
Next row