How to format specific cell in Excel

Dear UiPathers

I have an excel document I am looking through and want to find the position (row, column) in where the data is wrong. I only accept numbers in the Excel document, however, some cells have text. I have correctly detected which cells are wrong and which are right. Now comes the last part, where I need to format the cells which are wrong and then write them into another cell.

You may assume that the formating style is not important, however, for ease, let’s just say I want to change the “Fill” to “Red”.

You may also assume that both i and j are variables that change according to which cell we currently are in. I am using a for loop inside a for loop to determine i and j.

When I write to a cell I do the following…
Excel.Sheet(“Ark1”).Cell(UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(j+252)+(i+1).ToString)

This let’s me correctly write to a specific cell. For formatting I want to do something specific, so if the cell that is wrong is, for example, D7, then I want D7 to be formatted with a “Red” “Fill”.

My initial idea was to just paste the above argument into the Format Cells activity, however, I get this following error when doing it…

Hope this makes sense, else do ask questions for ellaborations.

Translation of the error code: If Option Strict On is being used, then it is not possible to convert from ‘UiPath.Excel.ExcelValue’ to ‘UiPath.Excel.IReadRangeRef’.

Thanks and have a great day forward.

Hi @nmjvk ,

Could you try changing the Cell to Range and Check if it works ?

Excel.Sheet("Ark1").Range(UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(j+252)+(i+1).ToString+":"+UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(j+252)+(i+1).ToString)

If the above works, I would suggest to assign the value to a variable, so as to ease the repeated use of the same value.

1 Like

Dear @supermanPunch

Perfect, that works just I want it. Thank you so much.

1 Like

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