How to set font color to red or green based on column value in excel

I have 3 columns. If column status contains value “green” then text font should change to green color.
If column status contains value “red” then text font should change to red color…
Please help anyone?

Hi @vnsatyasunil ,
To change format , color of cell, you can use VBA

regards,

1 Like

Hello @vnsatyasunil

Sequence
Read Excel Data →
Excel Application Scope
Excel Read Range SheetName=“YourSheetName” Range=“C:C” OutputDataTable=“dtExcelData”
Excel Application Scope

Loop Through DataTable →
For Each Row In dtExcelData
If Condition=“row(“Status”).ToString = ‘green’”
Apply Green Font Color →
Excel Application Scope
Excel Write Cell SheetName=“YourSheetName” CellAddress=“C” Value=“=C” FontColor=“Green”
Excel Application Scope
If
If Condition=“row(“Status”).ToString = ‘red’”
Apply Red Font Color →
Excel Application Scope
Excel Write Cell SheetName=“YourSheetName” CellAddress=“C” Value=“=C” FontColor=“Red”
Excel Application Scope
If
Add more conditions for other colors if needed →
For Each Row
Sequence

Thanks & Cheers!!!

Thanks in write cell how can we pass font color getting syntax error Please guide

@vnsatyasunil

  1. Use “Write Cell” activity.
  2. Specify the cell and value.
  3. In the “Font” property, use VB.NET syntax to set the font color, e.g., New System.Drawing.ColorConverter().ConvertFromString("Red").ToArgb() for red.

where is font property in this?

Hi @vnsatyasunil

You can try these steps

  1. Read Excel File
    Add Data Column: FormattedStatus

  2. For Each Row in DataTable
    If Row(“status”).ToString = “green” Then
    Assign: Row(“FormattedStatus”) = “<font color=”“green”“>” + Row(“status”).ToString + “”
    ElseIf Row(“status”).ToString = “red” Then
    Assign: Row(“FormattedStatus”) = “<font color=”“red”“>” + Row(“status”).ToString + “”
    Else

  3. Assign: Row(“FormattedStatus”) = Row(“status”).ToString
    End If & End For Each

  4. Write DataTable to Excel File

tried like this color not changing

use excel file activity is used then used for each row in excel
if currentrow.byfield(“column name”).equals(“Green”)
then format cells activity is used
In source field, given like this.
excel.sheet(“Sheet name”).range(“B”+(CurrentIndex.tostring))
but the output is wrong colour is changing but for red text also green font coming
Can anyone help on this please

Use the excel VBA activity and try the below code -

Sub ChangeFontColor(rowNumber As Integer)
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(“Sheet1”) ’ Replace “Sheet1” with the actual sheet name

If ws.Cells(rowNumber, "B").Value = "green" Then
    ws.Cells(rowNumber, "B").Font.Color = RGB(0, 128, 0) ' Green
ElseIf ws.Cells(rowNumber, "B").Value = "red" Then
    ws.Cells(rowNumber, "B").Font.Color = RGB(255, 0, 0) ' Red
End If

End Sub

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