How to loop and write

Hi Team,

I have an excel sheet, in one column I have number and contains blank and if 1 is there then to next that column it should write as Case1, and the number 2 and 3 continue, it should write Case2 next to 2 number

PFA,

Thanks

Hi [Sharanabasava,
You can go through this workflow

Thanks,
Rounak

Hey!

You can try out the following steps:

  1. Read the excel data into an DataTable say input_DT"
  2. Use a For each row in Datatable activity to loop through the records
  3. Inside for each
    if(Not String.IsNullOrEmpty(CurrentRow(“Xperia”).Tostring)
    then
    in Assign use IndexOfCurrentRow = Input_DT.Rows.IndexOf(CurrentRow)
  4. Use a Write cell activity in the and write the value as “Case”+CurrentRow(0).Tostring
  5. In the Range for the cell use “B” + (IndexOfCurrentRow +2).Tostring - Here adding 2 because the Index starts with 0 in Datatable and you have Headers in the Excel

Regards,
Rajeswari

1 Like

It did not work, if it worked for you can you send the xaml file

Hey,

Check out this xaml and the excel file where the output was written in B column.

Test.xlsx (8.9 KB)
Main.xaml (7.8 KB)

Regards,
Rajeswari

Thank you, but I need like this output
Pls find attachment
Test (2).xlsx (8.9 KB)

The above workflow will work the way you need. Please change in input file path to your desired Excel file and it will work.

sample output
image

Regards,
Rajeswari

But this is not matching, when we have 1 row as Case1, 2rows continuously Case2 and 3rows continuously as Case3

Thank you

Regards,
Sharan

In the first screen shot I have showed that sample

Can you confirm whether you need the output as this or

image

Regards,
Rajeswari

first as you shown

are you able to find any solution?

Thank you

Hey!

Yeah, please check this xaml if this works.

Main.xaml (13.1 KB)

Regards,
Rajeswari

Hay,

image

where 2 and 5 is there, it should write as Case2 but it is writing Case4

Hi Sharanabasava,

Please check and let me know if you get any difficulties.
FinalData.xlsx (9.2 KB)

Sample.xaml (10.6 KB)

Thanks,
Rounak

when I ran the bot, I am getting this has output

image

Hi Sharanabasava1,

if this output is As you expected then
Please Accept the Solution or else let me know

Thanks
Rounak

This is not the output what I was excepting,
Please find the below screen shot

image

Hi Rajeswari,

did you find any logic how to do? I am trying but not success

Thank you for your help

Hello @Sharanabasava1

Please confirm how you are getting this excel?

If you are adding the data to the excel through some process, then we need to think of a standardization in that process.