How to indicate a column of a Data Table in the variable

Hi, I would like the bot to read an excel file by matching email address. If the email and the excel file has the same/matching email address, I need the bot to take the next column information to be inserted into the next step which is a forwarding email.

Hi @mnurhaikal

Can you share some informative dummy screenshots on your use case?

Try this activity: Activities - Lookup Data Table

Hi @mnurhaikal

Try this way below:

  1. Use the Filter Data Table activity to filter rows in dataTable where the email matches your target email.

Input DataTable: dataTable

Output DataTable: filteredDataTable

• In the Filter Rows section:

• Column: [Email] (or the exact column name where the email is stored)

• Condition: =

• Value: targetEmail (the email address you’re searching for)

  1. After the filter, filteredDataTable will contain only the rows where the email matches targetEmail.

Use this command in the assign activity to take the e-mail

infoToForward = If(filteredDataTable.Rows.Count > 0, filteredDataTable.Rows(0)(“Information”).ToString, “No match found”)

Hi everyone i managed to solved it. Thanks! I actually keyed in "Excel.Sheet(“Sheet1”).

Hey @mnurhaikal,

Welcome to the community! :blush:

To achieve your requirement of reading an Excel file, matching an email address, and then retrieving information from the next column, here’s a step-by-step solution using UiPath:

Solution:

Step 1: Read the Excel File

  1. Use the “Excel Application Scope” activity.
  2. Inside it, use the “Read Range” activity to read the data into a DataTable (let’s call it dtEmails).

Step 2: Use a For Each Row to Loop Through the DataTable

  1. Use a “For Each Row” activity to iterate over dtEmails.

Step 3: Match the Email Address

  1. Inside the loop, use an “If” activity to check if the email matches:
    row("Email").ToString.Equals(targetEmail, StringComparison.OrdinalIgnoreCase)
    
    • Replace "Email" with your actual column name containing email addresses.
    • targetEmail is the email address you’re searching for.

Step 4: Retrieve the Next Column Value

  1. If the email matches, get the value from the next column:
    nextColumnValue = row("NextColumnName").ToString
    
    • Replace "NextColumnName" with the actual name of the column you want to retrieve.

Step 5: Use the Retrieved Value

  1. You can now use nextColumnValue for your forwarding email step.

Example in UiPath:

For Each row in dtEmails
    If row("Email").ToString.Equals(targetEmail, StringComparison.OrdinalIgnoreCase)
        nextColumnValue = row("NextColumnName").ToString
        Exit For
    End If
End For

Alternative: Use LINQ (If You’re Familiar with It)

You can also use LINQ for a one-liner solution:

nextColumnValue = (From r In dtEmails.AsEnumerable()
                   Where r("Email").ToString.Equals(targetEmail, StringComparison.OrdinalIgnoreCase)
                   Select r("NextColumnName").ToString).FirstOrDefault()

I hope this helps! Let me know if you need further clarification. :blush:

Best,
Chaitanya