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

Enric 81 Reputation points
2022-04-20T15:43:04.95+00:00

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

194700-image.png

The outcome would be the following:

194738-image.png

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("C2:C3").Select  

    '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
    2022-04-21T16:18:19.313+00:00

    Excel 365 Pro Plus with Power Pivot and Power Query.
    Plot and CF differences.
    No formulas, no VBA macro.
    https://www.mediafire.com/file/ioxvv7pqz27988y/04_21_22.xlsx/file
    https://www.mediafire.com/file/86az92069lf6flw/04_21_22.pdf/file

    0 comments No comments

  2. Enric 81 Reputation points
    2022-04-25T10:53:06.17+00:00

    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