Firstly, I will show a minimal example of my data and code that I still have, so it will be easier for me to explain my problem.
Consider the following data:
ID Esp DBH Cod
55 E_grandis 9.00
55 E_grandis 9.71 7
55 E_grandis 10.00
55 E_grandis 1.00 7
55 E_grandis 7.00 7
55 E_grandis 1
I am trying to check if lines with Cod = 7 have values greater than:
average of DBH - 1 * standard deviation of DBH.
In the above example, the average DBH is 7.34 and the standard deviation is 3.73. Therefore, DBHs should not exceed 3.61 (7.34 - 3.73) when they are labeled with Cod 7.
Cells D3 and D6 do not qualify because their DBH (C3 and C6) is greater than 3.61. Of all the lines with Cod 7, only C5 is less than 3.61.
I wrote the code below that displays a message box when such criteria are not met:
Sub Cod7()
Dim msg As String 'msg box
Dim ID As Range
Dim dbh_stdev As Double 'standard deviation of dbh
Dim dbh_avg As Double 'average of dbh
Dim not_dominated As Double 'criteria threshold (upper bound)
Dim cell_i As Range 'initial of array to compute average and standard deviation
Dim cell_e As Range 'end of array to compute average and standard deviation
msg = ""
Set cell_i = Range("C2")
Set cell_e = Range("C7")
dbh_stdev = WorksheetFunction.StDev(Range(cell_i, cell_e)) 'dbh standard deviation
dbh_avg = WorksheetFunction.Average(Range(cell_i, cell_e)) 'dbh average
not_dominated = dbh_avg - dbh_stdev 'upper bound
'searches cells with cod 7 on column Cod, and it displays a message box if
'DBH is greater than the 'not_dominated' variable value
For Each ID In Range("A2", Range("A2").End(xlDown))
If ID.Offset(0, 3) = 7 And _
ID.Offset(0, 2) <> 0 And _
ID.Offset(0, 2) > not_dominated Then
msg = msg & "Cod 7 on " & ID.Offset(0, 3).Address() & " is incorrect" & vbLf
End If
Next ID
If Len(msg) > 0 Then MsgBox msg
End Sub
, Esp (specie), , DBH .
> , .. .
, Esp: E_grandis E_citriodora.
ID Esp DBH Cod
55 E_grandis 9.00
55 E_grandis 9.71 7
55 E_grandis 10.00
55 E_grandis 1.00 7
55 E_grandis 7.00 7
55 E_grandis 1
55 E_citriodora 3.00
55 E_citriodora 2.00 7
55 E_citriodora 2.00 7
55 E_citriodora 1
55 E_citriodora 1
55 E_citriodora 0.50 7
DBH E_citriodora 1,88, - 1,03. Cod = 7 DBH 0,85 (1,88-1,03). C9 e C10 , C13.
"Esp"?