How to loop through rows and cells and compare two cells' values?

Enric 81 Reputation points

Hi all, I would need highlight a couple of cells related to every company and based to two different accounts (400 and 430) and where the substract of both values be <> 0.

Let me illustrate this with a screenshot


The outcome would be the following:


Snippet code, it is just an approach, isn't working at all:

Sub ni()

Set Rng = Range("C2:E7")

Dim rango As Range

For Each cell In Rng

Set rango = ActiveCell

If Abs(rango.Offset(1, 0).Value) - Abs(rango.Offset(y, 0).Value) < 0 Then

    Debug.Print "differents"  

    'Range(Cells(3, 3), Cells(y, x)).Select  
    With Selection.Interior  
        .Pattern = xlSolid  
         .PatternColorIndex = xlAutomatic  
         .ThemeColor = xlThemeColorAccent4  
         .TintAndShade = 0.599993896298105  
         .PatternTintAndShade = 0  
    End With  

End If
y = y + 1

Next cell

End Sub

Thanks in advance,

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,715 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Herbert Seidenberg 1,191 Reputation points

    Excel 365 Pro Plus with Power Pivot and Power Query.
    Plot and CF differences.
    No formulas, no VBA macro.

    0 comments No comments

  2. Enric 81 Reputation points

    Thanks for the message, it is something that still needs to be done using VBA... in this concrete case due to the dataset is read from a SSIS package...

    0 comments No comments