I need to perform some validation in Excel

Hey all,

I need to perform some vadilation in Excel. Help me with this. I’ve attached the files for your reference.

ExcelValidationTestFile.xlsx (14.6 KB)
RPA_Control.xlsx (9.9 KB)

I have an Excel file where the first row contains the headers.

I want to process only the rows where Column B has a value and is not empty.

I have another Excel file with a sheet named “Main”. Cell B1 contains the “From Date” and Cell B2 contains the “To Date”.

Conditions :

Check Column C, If the value is “Recurring JV”, highlight the cell in yellow & stop the workflow.

If the date is not between the “From Date” and “To Date”, highlight the cell in yellow & stop the workflow.

If the value in Column J is not “Approved”, highlight the cell in yellow & stop the workflow.

If the value in Column L is not “Eligible for SAP Posting”, highlight the cell in yellow & stop the workflow.

Thank you,
Uio

1 Like

Hi @uio

Here is my solution. Please follow along.

The Workflow:

Explanation:

1. Read range Workbook (dt_rpaControl) and Multiple Assign to extract the FromDate and ToDate from Main Excel:

fromDate = CDate(dt_rpaControl.Rows(0).Item(1))
toDate = CDate(dt_rpaControl.Rows(1).Item(1))

2. Read Range Workbook (dt_excelValidation) and Assign (dt_primaryRows) to extract the primary rows from the Input Excel by considering the condition you said “process only the rows where Column B has a value and is not empty.”

dt_primaryRows = dt_excelValidation.AsEnumerable().
    Where(Function(row) Not String.IsNullOrWhiteSpace(row(1).ToString())).
    CopyToDataTable()

3. Invoke Code to identify the cells to colour. The output is a list of cell IDs:

The code:

For Each row As DataRow In dtPrimary.Rows
	Console.WriteLine("Trying to find row in dtFull: " & row(1).ToString())
	Dim rowIndex As Integer = -1

	For i As Integer = 0 To dtFull.Rows.Count - 1
    	If dtFull.Rows(i)(1).ToString().Trim() = row(1).ToString().Trim() Then
        	rowIndex = i
        	Exit For
    	End If
	Next
	
	Console.WriteLine("Row index in dtFull: " & rowIndex)
    If rowIndex = -1 Then Continue For

    Dim excelRow As Integer = rowIndex + 2 ' Add offset for header

    ' --- Column C ---
	Console.WriteLine("Column C value is : " & row(2).ToString().Trim())
    If row(2).ToString().Trim().Equals("Recurring JV") Then
        cellsToColor.Add("C" & excelRow.ToString())
    End If

    ' --- Column E ---
	Console.WriteLine("Column E value is : " & row(4).ToString())
Dim dateVal As DateTime
Dim dateString As String = row(4).ToString().Trim()

If DateTime.TryParseExact(dateString, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, dateVal) Then
    If dateVal < FromDate OrElse dateVal > ToDate Then
        cellsToColor.Add("E" & excelRow.ToString())
    End If
End If

    ' --- Column J ---
	Console.WriteLine("Column J value is : " & row(9).ToString().Trim())
    If Not row(9).ToString().Trim().Equals("Approved", StringComparison.OrdinalIgnoreCase) Then
        cellsToColor.Add("J" & excelRow.ToString())
    End If

    ' --- Column L ---
	Console.WriteLine("Column L value is : " & row(11).ToString().Trim())
    If Not row(11).ToString().Trim().Equals("Eligible for SAP Posting", StringComparison.OrdinalIgnoreCase) Then
        cellsToColor.Add("L" & excelRow.ToString())
    End If
Next

The arguments

4. Excel Application Scope targeting the input excel, and use a For each to iterate through the list of Cells, and the use Set Range Color activity to colour the cells. Refer below screenshot:

THE OUTPUT:
As you can see below, the output is as you desired

Here, is some reference from the Log messages, to show you the Console.Write from the Invoke Code, and also the Locals Panel. This will give you clarity:


Note: The Invoke Code is given by LLM, But it took an Hour to debug and customise to the Query. Please be considerate. Thank You

If this solves your issue, Do mark it as a solution
Happy Automation :star_struck:

1 Like

Hi @V_Roboto_V ! Thank you for spending time to help me. Can you please share the xaml file ? It will be helpful for me to refer.

Sure @uio

Here, is the file:
Main.xaml (25.9 KB)

If this solves your issue, Do mark it as a solution
Happy Automation :star_struck:

Thank you so much for the support.

1 Like

@V_Roboto_V

I tried to re-create this method in another rpa tool and I get this error.

I can’t import “System.Data.DataSetExtensions”.

How do I fix this ?

1 Like

Could you try this instead:

dt_primaryRows = dt_excelValidation.Select("Len(Trim([Request Number])) > 0").CopyToDataTable()

Output:

1 Like

I found this and tried. It worked.

Thank you @V_Roboto_V

1 Like

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