How to write a value in an excel cell if another cell is empty?

Hi,
image

If Activity Type is empty I need to write 70002 in Sales Code column if not I need to write 70001.
I tried for each loop but it skips some rows and gives wrong results.
This is my for each loop. I don’t know what I am missing?

Thanks.

@makboga

I see it as filtereddata…are you using any filters? If yes then may be some data that is required might be filtered…

Please run in debug mode…add a breakpoint on for each and check if the datatable is having full data…

Cheers

@makboga Check this below attached workflow,
Uipath_ExcelUpdation.xaml (5.9 KB) and Input file which I have used
InputFile.xlsx (8.8 KB)

Hope this may help you :slight_smile:

I tried what you said when it sees the empty cell it goes back to previous cell and change it.
For first two row it is working it is writing 70001 but when it comes to third row it goes back to previous sales code and change it to 70002.

@makboga

I guess you need to give plus 2…and even first i dont think is correct then…one is for header and other is because idx in loop starts from 0 but you have to write it fiest cell when zero…so add 2

Cheers

Hi @makboga ,

Is this the output you were looking for?
image

If so, then could you give this workflow a try and let us know if it works out for you?

//Invoke Code
dt.AsEnumerable().ToList().ForEach(sub(row) row("Sales Code") = If(IsNothing(row("Activity Type")) OrElse String.IsNullOrEmpty(row("Activity Type").ToString.Trim),"70002","70001"))

UpdatesSalesColumn.xaml (7.0 KB)

Kind Regards,
Ashwin A.K

Thank you so much.

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