How to Find the difference between two cell values and compare it with other cell value in Excel?

Hi Community,

image

I would like to know what would be the data type for A,B,C columns. The values are dynamic. It can be String, number, decimals, etc

So, I need to find the difference between A and B and verify if it’s matching with C or not except last column . (Sometimes A value can be bigger, and sometimes B value can be bigger)

Approach I Tried is throwing error at Get row item activity. If it’s output variable is String type.
If I change it to Double, it is throwing TEXT is not a valid value for Double.
If I change to Generic Value, In If condition(A isNumeric = true AND B isNmeric = True) , It’s throwing error.

Any Guidance would be appreciated :slight_smile:
Thanks in Advance :slight_smile:

Hi @Vaishnav_Tej

You can use the Generic Value data type for all three columns. Try the following query in Invoke Code activity:

Dim aValue As Double = 0
Dim bValue As Double = 0
Dim cValue As String

Dim isANumeric As Boolean = IsNumeric(row("A").ToString())
Dim isBNumeric As Boolean = IsNumeric(row("B").ToString())

If isANumeric AndAlso isBNumeric Then
   
   Double.TryParse(row("A").ToString(), aValue)
   Double.TryParse(row("B").ToString(), bValue)
   Dim difference As Double = Math.Abs(aValue - bValue)

   cValue = row("C").ToString()
   If Not String.IsNullOrEmpty(cValue) AndAlso IsNumeric(cValue) AndAlso difference = Convert.ToDouble(cValue) Then
       [YOUR CODE FOR MATCHING BLOCK]
   Else
       [YOUR CODE FOR NON MATCHING BLOCK]
Else
   [VALUES ARE NOT DOUBLE BLOCK]

End If

Catch ex As Exception
   [EXCEPTION HANDLING BLOCK]
End Try

Hope this helps,
Best Regards.

Hi,

thanks for your code.

Else
[VALUES ARE NOT DOUBLE BLOCK]

---- Does this work for integers ?

@Vaishnav_Tej

Yes, it works. Using double just ensures the management of large/decimal point data.

Best Regards.