Hello,
I am trying to highlight anomalous values in my data by colouring the cell. I was kindly given a macro by offthelip last year which was really usefull but now I have much more data and the problem is that the macro highlights the cells either side of the anomaly as well. I havent been able to improve the macro myself. Is there a better mathematical expression for "mecells" that will select just the anomalous value to highlight? here is the macro and data example.
Sub testyellow()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 30))
For I = 3 To lastrow
For j = 2 To 25
mecells = (inarr(I, j - 1) + inarr(I, j + 1)) / 2
Delta = Abs(mecells - inarr(I, j))
If Delta >= 0.004 Then
With Range(Cells(I, j), Cells(I, j)).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 255, 0) 'yellow
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next j
Next I
End Sub
I am trying to highlight anomalous values in my data by colouring the cell. I was kindly given a macro by offthelip last year which was really usefull but now I have much more data and the problem is that the macro highlights the cells either side of the anomaly as well. I havent been able to improve the macro myself. Is there a better mathematical expression for "mecells" that will select just the anomalous value to highlight? here is the macro and data example.
Sub testyellow()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 30))
For I = 3 To lastrow
For j = 2 To 25
mecells = (inarr(I, j - 1) + inarr(I, j + 1)) / 2
Delta = Abs(mecells - inarr(I, j))
If Delta >= 0.004 Then
With Range(Cells(I, j), Cells(I, j)).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 255, 0) 'yellow
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next j
Next I
End Sub
Beam2 2022.xlsm | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | |||
1 | 73.4157 | 73.41557 | 73.41576 | 73.41544 | 73.41579 | 73.41525 | 73.41482 | 73.41538 | 73.41531 | 73.41539 | 73.41525 | 73.41563 | 73.41502 | 73.41547 | 73.41492 | 73.41541 | 73.41563 | 73.41584 | 73.4152 | 73.41562 | 73.41531 | 73.41537 | 73.41511 | 73.41494 | 73.41538 | ||
2 | 73.41315 | 73.41335 | 73.41324 | 73.41319 | 73.41325 | 73.41312 | 73.41306 | 73.41303 | 73.41318 | 73.41303 | 73.41315 | 73.41302 | 73.41314 | 73.41317 | 73.41311 | 73.41319 | 73.41318 | 73.41311 | 73.41311 | 73.41316 | 73.41325 | 73.41307 | 73.41313 | 73.41328 | 73.41306 | ||
3 | 73.41209 | 73.42255 | 73.41192 | 73.41206 | 73.41135 | 73.41229 | 73.47526 | 73.41032 | 73.41225 | 73.41213 | 73.36955 | 73.41216 | 73.41208 | 73.35071 | 73.4123 | 73.412 | 73.41247 | 73.41185 | 73.412 | 73.41207 | 73.41248 | 73.41222 | 73.41206 | 73.36831 | 73.41209 | ||
4 | 73.41586 | 73.4155 | 73.41531 | 73.41535 | 73.41516 | 73.41534 | 73.41612 | 73.41525 | 73.41521 | 73.41589 | 73.41547 | 73.41526 | 73.41534 | 73.41495 | 73.41544 | 73.41544 | 73.41602 | 73.41518 | 73.41459 | 73.41457 | 73.41458 | 73.41534 | 73.4148 | 73.4154 | 73.41493 | ||
5 | 73.41544 | 73.41534 | 73.4154 | 73.41518 | 73.41522 | 73.41566 | 73.4155 | 73.41586 | 73.41544 | 73.41528 | 73.41508 | 73.41556 | 73.41551 | 73.4156 | 73.41539 | 73.41488 | 73.4156 | 73.41525 | 73.41531 | 73.41508 | 73.41531 | 73.41523 | 73.41573 | 73.41567 | 73.41564 | ||
6 | |||||||||||||||||||||||||||
7 | |||||||||||||||||||||||||||
8 | -0.01045 | 0.010627 | -0.00015 | 0.000718 | -0.00095 | -0.06297 | 0.062966 | -0.06494 | 0.001938 | -0.00012 | -0.04258 | 0.04261 | -8.4E-05 | -0.06137 | 0.061592 | -0.0003 | 0.000473 | -0.00062 | 0.000145 | 7.6E-05 | 0.000412 | -0.00027 | -0.00015 | -0.04376 | 0.043777 | ||
Sheet5 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A8:F8 | A8 | =A3-B3 |
G8:Y8 | G8 | =G3-F3 |