Extract numbers only from Excel column

Hi,

I have the excel as shown below and I need to remove the front Characters and the space in between and keep only the numbers and put the whole in a new column in a new excel sheet. Here’s the excel file.
Can you help please?

Thanks!

UIPath_Excel_Scratch (2).xlsx (6.8 KB)

Hi @Yudhisteer_Chintaram1

Try like this

  1. Add a column named **Modified Product ID ** in the excel

  2. then use read range to read the excel file and store in dt1

3.Next use invoke code activitiy with dt1 as In/Out argument

Use below code in that activitiy

dt1.AsEnumerable().ToList().ForEach(Sub(row) row(“Modified Product ID”)= System.Text.RegularExpressions.Regex.Match(row(“Product ID”).ToString, “[^A-Za-z]”).Value.ToString)

Then after invoke code, use write range activitiy to write the updated dt1

Hope it helps you

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

Hi @Yudhisteer_Chintaram1 ,

An alternative to invoke code would be this simple workflow:

System.Text.RegularExpressions.Regex.Replace(row.item(2).ToString, “[a-zA-Z]”, “”).Trim

More about regex you can find here: https://forum.uipath.com/t/regex-help-tutorial-megapost-making-your-first-regex-post-reusable-regex-patterns-regex-troubleshooting-sample-workflow-and-more/238791

Demo file: ExtractDigits.xaml (6.2 KB)

Best regards,
Marius

2 Likes

It worked but with an excel sheet of about 30 columns, I get this error:

Assign: Exception has been thrown by the target of an invocation.

@Yudhisteer_Chintaram1

you are missing to add data column or you are passing the wrong column index to the assign row.item()

Thanks!

If there is an option to change the solution, Please mark @Marius_Puscasu as the Solution…
I just highlighted the issue…

1 Like

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