Conditional formatting in excel sheet if yes value there in column a then It Should appear in red

Option 1: Using LINQ (C#)

  1. Read the Excel data into a DataTable using the “Read Range” activity.
  2. Use LINQ to filter and modify the data based on the “Attribute A” column.
  3. Update the Excel file with the modified data using the “Write Range” activity.

var filteredData = dtData.AsEnumerable()
.Select(row =>
{
if (row.Field(“Attribute A”) == “Yes”)
row.SetField(“Attribute A”, “Dark Red”);
else if (row.Field(“Attribute A”) == “No”)
row.SetField(“Attribute A”, “Green”);
return row;
})
.CopyToDataTable();

dtData = filteredData;

Option 2: Using VBA Script (Excel Macro)

  1. Create an Excel VBA macro to perform the conditional formatting based on your criteria.
  2. Save the macro-enabled Excel file.
  3. Use the “Execute Macro” activity in UiPath to run the VBA macro. Provide the path to the Excel file and the macro name.

Sub FormatData()
Dim ws As Worksheet
Dim cell As Range

Set ws = ThisWorkbook.Sheets("YourSheetName") ' Replace with your sheet name

For Each cell In ws.Range("A2:A" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row)
    If cell.Value = "Yes" Then
        cell.Interior.Color = RGB(139, 0, 0) ' Dark Red
    ElseIf cell.Value = "No" Then
        cell.Interior.Color = RGB(0, 128, 0) ' Green
    End If
Next cell

End Sub

Cheers! :slight_smile:

1 Like