How to format a cell in Excel while using For Each Row

I am iterating through a spreadsheet using For Each Row. I am also using VLookup to find values to write to particular cells.

How do I format a particular cell while writing data to it?

image

Here I am writing the value “Green” to a cell in the CurrentRow, I would like to change the fill color of this cell to Green.

I know I can use a Format Cells activity, but I’m not sure how to find the range of the cell from the CurrentRow.

Is there an easy way to find the range of the cell? Or an easy way to format the cell that I am writing too?

@james.harvey

there is a currentindex property in for loop…which will give you the currentrow index…can use it to know the rowcount…

It generally starts from zero so add 2 or 3 depending on the row where data starts

Cheers

Hi @james.harvey ,

Please try this

Thanks

Hi @james.harvey - Hope below video would help you. Please look at before ending part as it has format cells component

(176) How to do an Excel VLOOKUP in UiPath (Full Tutorial) - YouTube

How do I find the currentindex for the row?

@james.harvey

To get the index

DTname.Indexof(Columnname).ToString

dt1.Rows.IndexOf(row).ToString

Regards

Thanks for all of the help. I was able to figure out a way to do what I needed based on all of the feedback that I received. I don’t feel that this is the proper way to do this, but it works.

image

The expression builds a range for Column L using the index of the current row of the Excel sheet + 1 (due to header row).

1 Like

@james.harvey

This is the currentindex i am mentioning…glad you found it

One more way is to use conditional formatting on a file and use same file as template always

Cheers

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