I have to sheets , one has "titles " in column B and is missing “text” in column C
the other has titles in A and the text in B
I need the tool to find the right text to the right tittles since they are not in the same order
Hey @gerdonline
-
Use read range to read the entire sheet and save output to variable
dtSheet1. -
Next, use read range for the second sheet and save output to variable
dtSheet2. -
Use For Each Row activity to iterate through
dtSheet1
Inside this loop, use another For Each Row activity to iterate throughdtSheet2
Use if activity to compare the titles:currentRow1("titles").ToString = currentRow2("titles").ToString
Then: Assign the matching text todtSheet1:currentRow1("text") = currentRow2("text") -
After updating
dtSheet1with the missing texts, write it back to the first Excel sheet or a new sheet used Write Range activity.
Alternatively you can use (assign to datatable variable):
(From row1 In dtSheet1.AsEnumerable()
Join row2 In dtSheet2.AsEnumerable()
On row1.Field(Of String)("titles") Equals row2.Field(Of String)("titles")
Select dtSheet1.LoadDataRow(New Object() {
row1("titles"),
row2("text")
}, False)).CopyToDataTable()
I highly suggest doing the free training on the academy.uipath.com web site. That way you’ll understand basic things like how to work with Excel files. For example…
Hi,
To match and copy the text to the corresponding titles between two sheets where the titles are not in the same order, you can use the VLOOKUP function in Excel or the Lookup Data Table activity in UiPath. Here’s how you can do it in both:
Using Excel VLOOKUP function:
- Open your Excel workbook with both sheets.
- Go to the sheet where the column B has titles and column C is missing the text.
- Click on the first cell in column C where you want to paste the text.
- Enter the following VLOOKUP formula:
=VLOOKUP(B2, Sheet2!A:B, 2, FALSE)
- Here
B2is the reference to the title in the current sheet.Sheet2!A:Bshould be replaced with the actual name of your other sheet and the range where titles and texts are located.2is the column index in the range where the text is found (B column in the second sheet), andFALSEspecifies that you want an exact match. - Press Enter, and if there’s a matching title in the other sheet, the corresponding text will appear.
- Drag the fill handle (a small square at the bottom right corner of the cell) down to fill the formula for the other cells in column C.
Using UiPath with Lookup Data Table activity:
- Use the
Excel Application Scopeactivity to open the Excel file. - Use
Read Rangeactivities to read the data from both sheets into DataTable variables, let’s saydtTitlesWithTextfor the sheet with complete data anddtTitlesMissingTextfor the sheet with missing texts. - Use a
For Each Rowactivity to iterate throughdtTitlesMissingText. - Inside the loop, use the
Lookup Data Tableactivity:
- For the
DataTableproperty, usedtTitlesWithText. - For the
LookupValueproperty, userow("titles").ToString, assuming “titles” is the column name for titles. - For the
TargetColumnproperty, use the column index or name where the text is stored indtTitlesWithText. - For the
ColumnNameorColumnIndexproperty, use the index or name of the column with titles indtTitlesWithText. - For the
Outputproperty, create a variable to store the found text.
- Use an
Assignactivity to set the value in thedtTitlesMissingTextDataTable with the text found by theLookup Data Tableactivity. - After the loop, use a
Write Rangeactivity to write the updateddtTitlesMissingTextback to the Excel sheet.
Remember to use proper exception handling in UiPath to manage cases where a matching title is not found. The VLOOKUP method in Excel is straightforward and suitable for a quick task.
Thanks
Thank you Piotr, much I need learn. ![]()
Thank you all of you , will take the time and report when done
vlookup didn’t work because the spelling is to different (sometimes with capital letters , sometimes in ")