Macro for coloring cells depending on values and presenting them

PeriGr 11 Posts Monday July 17, 2017Registration date August 12, 2017 Last seen - Jul 17, 2017 at 08:22 AM - Latest reply: TrowaD 2340 Posts Sunday September 12, 2010Registration dateModeratorStatus April 19, 2018 Last seen
- Jul 18, 2017 at 12:09 PM
Hello guys!!

I have an excel file with 2 columns of percentages. The first column has theoretical values of an experiment and the second column has the real values that were measured in an experiment. I want to create a macro which will be able to compare the values of the cells for every row(2 cells every row since we have 2 columns) and when the difference of the percentage is more than 5 units then I want to color the row and appear it in another pop-up or excel sheet! and this process has to be for every row. SO finally I want to have another sheet in excel which will have all the rows which had bigger difference than 5!

Can you please help me ??
See more 

1 reply

Reply to this topic
TrowaD 2340 Posts Sunday September 12, 2010Registration dateModeratorStatus April 19, 2018 Last seen - Jul 18, 2017 at 12:09 PM
0
Helpful
Hi PeriGr,

In the code below the source sheet is called Sheet1 and the destination sheet is called Sheet2.

Here is the code:
Sub RunMe()
Dim mDiff As Double
mDiff = 0.05

Sheets("Sheet1").Select

For Each cell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    If cell.Value - cell.Offset(0, 1).Value > mDiff Or cell.Offset(0, 1).Value - cell.Value > mDiff Then
        cell.EntireRow.Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        cell.EntireRow.Interior.ColorIndex = 3
    End If
Next cell
End Sub


Best regards,
Trowa
Respond to TrowaD