Using for each; do substring and to paste in each line items into excel

Hello all, I need some guidance here.

I need to perform substring activity to retrieve the number as per highlighted in yellow.

image

I used log message and it seems like I manage to extract out the numbers that I need.

Next, I will need to paste the numbers into my excel file into column Y (under AMT number column). This file has hundreds of line items, hence the expectation is to ensure every number able to paste accordingly into the right line.

image

However, it seems that I have an error showing below. When the robot runs, the excel file is not even open.

So my question here is:

  1. How do i resolve this error?
  2. Do i need to build data table in order to ensure all numbers paste accordingly? Or i can directly use below assign activity. Is this the correct way to do this?

image

Please help to advice. Thank you.

Hi @Farhah ,

You need to identify the row index of the target excel to update the value.

use excel application scope and write cell activity.

1 Like

dont use the workbook version of write cell , as it makes the robot open and close the workbook multiple times since its in a loop, you got that error because robot tried to open the workbook but it was opened already.

Instead you should use excel application scope outside of your “For each row”, then pass in your excel path into the excel application scope, this way your excel is only opened once

image

Then for “write cell activity”, use the excel version instead of the workbook version

image

Hello… Thank you for your guidance. I have update accordingly, however now I have got this error message. Do you have any suggestion on how do I proceed from here?

Hello, thank you for your response. Appreciate it. Here what I have done. As per advice by Jack Chan, I should put the excel scope outside of for each activity. However i am now getting below error. Kindly help to advice on this please. Thank you.

Hi @Farhah

Please check the scope of dtAMT datatable
in varaible section

Please make the scope of dtAMT to whole sequence

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

1 Like

Please check Row count of datatable (dtAMT)

I think dtAMT is empty

In message box write command

dtAMT.Rows.Count

1 Like

Hello @NIVED_NAMBIAR Thank you for responding :slightly_smiling_face:

The ‘dtAMT’ is set to whole sequence. It was located on sequence number 3 where here i did some necessary filtering on the excel

I am now stuck at sequence number 4, where the input i put ‘dtAMT’

Where did i do wrong?

Did u check whether there is any rows in dtAMT like as @Shivam_Kushwaha said
Please try dtAMT.Rows.Count to check the no of rows in dtAMT
before using for each row

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed:

1 Like

Hello @NIVED_NAMBIAR @Shivam_Kushwaha

Thank you for your guidance. This is the screenshot of the msg box that I have done. Kindly refer below.

can you upload your workflow here

Hi @Farhah

Please put Same message box in 3rd sequence after Filter data table activity

And share the result

Regards,
Shivam

Hello @Shivam_Kushwaha ,

It seems like it was able to detect the row numbers. Here you go:
image

Did check whether there are 2 dtAMT varaibles in different scope?

click inside your for each loop in sequence 4, then go to variables and delete the dtAMT variable.

Then go back to sequence 3, click inside variables and check if dtAMT exists, if it does it means you had 2 dtAMT variables, and you just deleted the duplicate one, you should then change the scope of the one in sequence 3

Hello @jack.chan @NIVED_NAMBIAR

I have checked there is only 1 variable for dt AMT. Somehow, i tried to close my UiPath application and re run again~ it seems to work fine now. I have done no changes as per my last update. Anyways, it works. Thank you for all your suggestion. It really helps.

However now, seems like when it paste it paste into the same cell. I have created a new variable called ‘celltopaste’ as below. The idea is to paste the AMT number into column Y, starting from Y2 till the end of the rows. Any suggestion on how to resolve this? Kindly help to advice. Thanks.

image

U had to use something like

counter=2

In write cell

Cell : “Y”+counter.ToString

counter=counter+1

It should be a iterative

Hello @NIVED_NAMBIAR ,

Do you mean something like this?

Yes @Farhah

Hello @NIVED_NAMBIAR ,

Unfortunately it doesn’t work. The numbers will keep replacing in cell Y2.

image