How can I apply conditional formatting to a range of cells based on their values using VBA? I need to highlight cells in different colors depending on whether their values fall within certain ranges.
postwick
(Paul Ostwick)
August 6, 2024, 8:44pm
2
There are tons of posts on this already. Here is a tutorial I made.
This was done using UiPath.Excel.Activities 2.16.2 - it may work with older versions, I don’t know when these activities were introduced. It likely works with newer versions also.
This particular code I’m showing sets negative numbers to red, but you could of course also put a Format Cells activity into the Then block to format positive numbers green, for example.
Basic steps:
Excel Process Scope
Use Excel File
– For Each Excel Row
— If to determine positive or negative
---- Format Cell…
pradeep931
(Pradeep Bandharam)
August 7, 2024, 6:35am
3
Hi @hassan_sohail
Please find the below thread consists both VBA and LINQ
Option 1: Using LINQ (C#)
Read the Excel data into a DataTable using the “Read Range” activity.
Use LINQ to filter and modify the data based on the “Attribute A” column.
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;
})
.Copy…
This is not supported right now.