How to find the rows with Blue color cells in Excel

I have this excel file:
This image shows a spreadsheet containing a list of items with various attributes including ID numbers, quantities, prices, and boolean values. (Captioned by AI)

I want to extract the rows that has blue color values. I was trying to use Get cell color activity but it only gives you a value for a single cell.
Thanks for any help.

Hi @chauhan.rachita30

Please refer to the video below where the presenter uses the “Invoke VBA” code to retrieve the color code. Using this method, you will be able to achieve the desired rows.

Or
Try with the Balareva easy excel activities

Use for each excel to iterate all cells

To find rows with blue-colored cells in Excel using UiPath, follow these steps:

  1. Use Excel Application Scope to open the Excel file.
  2. Read Range activity to load the data into a DataTable.
  3. Loop through each cell using a For Each Row or nested loops.
  4. Inside the loop, use the Get Cell Color activity to check the cell’s background color.
  5. If the color matches blue (RGB or Hex value), store the row index or perform any action you need.

This approach allows you to identify blue-colored cells effectively.

We can use this code inside Invoke Code activity in UiPath:

stringError = “”
Dim var_app As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Dim var_workbook As Microsoft.Office.Interop.Excel.Workbook
Dim var_worksheet As Microsoft.Office.Interop.Excel.Worksheet
out_list_RowNumbers = New List(Of Integer)

Try
'Initialize the Excel application, workbook, and worksheet objects

'Open the Excel workbook and retrieve the first worksheet
var_workbook = var_app.Workbooks.Open( FilePath) ' Ensure the correct path
var_worksheet = CType(var_workbook.Worksheets(1), Worksheet) ' First worksheet

'Set Excel application visibility and disable alerts
var_app.Visible = False
var_app.DisplayAlerts = False

    'Check for blue font color and iterate through each cell in the worksheet's used range
Dim blueColor As Integer = ColorTranslator.ToOle(System.Drawing.Color.Blue)
    For Each cell As Microsoft.Office.Interop.Excel.Range In var_worksheet.Range(CellRange)
    ' Check if the font color is blue (RGB 0, 0, 255)
    If CInt(cell.Font.Color) = blueColor Then
		             Console.WriteLine(cell.Row.ToString)
		          out_list_RowNumbers.Add(cell.Row) ' Add the row number to the output list
    End If
Next
' Save and close the workbook (optional if there are no changes)
' var_workbook.Save()  

Catch ex As Exception
stringError = “An error was received while attempting to invoke code at '” + ex.Source + "': " + ex.Message
Console.WriteLine(stringError)
Finally
’ Release COM objects and set them to Nothing
If var_worksheet IsNot Nothing Then Marshal.ReleaseComObject(var_worksheet)
If var_workbook IsNot Nothing Then Marshal.ReleaseComObject(var_workbook)
If var_app IsNot Nothing Then Marshal.ReleaseComObject(var_app)
var_worksheet = Nothing
var_workbook = Nothing
var_app = Nothing
End Try

These are the arguments:

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