question

EnricVives-8498 avatar image
0 Votes"
EnricVives-8498 asked EnricVives-8498 answered

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

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-vba-devoffice-scripts-excel-dev
image.png (10.0 KiB)
image.png (9.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HerbertSeidenberg-6295 avatar image
0 Votes"
HerbertSeidenberg-6295 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EnricVives-8498 avatar image
0 Votes"
EnricVives-8498 answered

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...

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.