Implementing an efficient way to VLOOKUP a table by trying a LINQ if possible

Hi,

Good Day.

Source.xlsx

Actual.xlsx

I have this manual process. Shown files above are the Source.xlsx and Actual.xlsx.

First step: Copy the highlighted rows from Source.xlsx where the basis is the current date or today’s date. Then paste the highlighted rows to the Sheet1 of the Actual.xlsx (highlighted in Yellow)

Second Step: In the Actual sheet of Actual.xlsx, apply this VLookUp Formula: =VLOOKUP(@C:C,Sheet1!E:F,2,0) in the column beside the Reference Number (highlighted in green)

May I ask for help to know what is the most efficient way to automate this one even if it is composed of thousands of rows? Can we implement LinQ instead of VLookUp formula and generate the same output efficiently?

Kindly see attached files for Source.xlsx and Actual.xlsx. Thank you.

Actual.xlsx (10.5 KB)
Source.xlsx (10.2 KB)

Best regards,
Llessur

Hi @Llessur

If you use excel activities it will take some more time than linq queries when you have a large number of data.

You can use linq queries but it will take sometime to write the datatable back to excel.

Select the approach based on your requirement and data size.

Hope it helps!!

1 Like

Hi @Llessur

Can you try the below

Code:

For Each row1 As DataRow In dt_Actual.Rows
    Dim ReferenceNumber As String = row1("Reference Number").ToString()
    Dim foundRow As DataRow = dt_Source.AsEnumerable().FirstOrDefault(Function(r) r(4).ToString() = ReferenceNumber)
    If foundRow IsNot Nothing Then
        row1("New Col") = foundRow(5)
    End If
Next

Output:

Sequence4.xaml (11.5 KB)

Note: Uncheck Add Headers option in Source DataTable i.e., dt_Source

Regards,

1 Like

Hi @lrtetala the provided .xaml file writes the output in the Sheet1 instead of writing it in the Actual sheet

Hi @Llessur

You can change the value of the Path and Sheet Name in the Write Range Workbook as per your requirement in the solution given by @lrtetala

1 Like

I the write range workbook activity, give Active instead of Sheet 1 in sheet name field… @Llessur

Hope it helps!!

Hi @V_Roboto_V @lrtetala @mkankatala thank you so much for your help. I’ve unchecked the Add Headers in the Read Range for Source.xlsx and Write Range for Actual.xlsx. Thank you.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.