Cyber_Snowman
New Member
- Joined
- May 1, 2019
- Messages
- 5
Below are my attempt to identify the row(and time) when all four data (column F to I) are within temperature perimeter. I keep track of row that fulfill the requrimet in the "goodRow()" array. What I need help with is getting the right row when the check is all done and have them highlighted. As of now, the highlighted cell are from the "A" row which I think is due to the problem retrieving data from array.
Code:
sub aplication()
Dim goodRow() As Long
Dim dataStart As Range, dataEnd As Range, dataRange As Range, checkRange As Range
Dim firstGoodTime As Range, lastGoodTime As Range, tempCell As Range
Dim lowGoodTemp As String, highGoodTemp As String
Dim goodCellCount As Integer, goodRowCount As Integer
'code body
goodRowCount = 0
For i = dataStart.Row To dataEnd.Row
'For i = 116 To 120
'MsgBox (i)
If goodCellCount = 4 Then
goodRowCount = goodRowCount + 1
'MsgBox (goodRowCount)
ReDim Preserve goodRow(0 To goodRowCount)
goodRow(goodRowCount) = i - 1
'MsgBox (goodRow(goodRowCount))
'MsgBox (goodRow(1))
End If
goodCellCount = 0
'start the check for good temp
Set tempCell = Range("F" & i)
If tempCell.Value >= lowGoodTemp And tempCell.Value <= highGoodTemp Then
tempCell.Interior.Color = RGB(198, 239, 206)
tempCell.Font.Color = RGB(0, 97, 0)
goodCellCount = goodCellCount + 1
End If
Set tempCell = Range("G" & i)
If tempCell.Value >= lowGoodTemp And tempCell.Value <= highGoodTemp Then
tempCell.Interior.Color = RGB(198, 239, 206)
tempCell.Font.Color = RGB(0, 97, 0)
goodCellCount = goodCellCount + 1
End If
Set tempCell = Range("H" & i)
If tempCell.Value >= lowGoodTemp And tempCell.Value <= highGoodTemp Then
tempCell.Interior.Color = RGB(198, 239, 206)
tempCell.Font.Color = RGB(0, 97, 0)
goodCellCount = goodCellCount + 1
End If
Set tempCell = Range("I" & i)
If tempCell.Value >= lowGoodTemp And tempCell.Value <= highGoodTemp Then
tempCell.Interior.Color = RGB(198, 239, 206)
tempCell.Font.Color = RGB(0, 97, 0)
goodCellCount = goodCellCount + 1
End If
Next i
Set firstGoodTime = Range("B" & LBound(goodRow) + 1)
'MsgBox (firstGoodTime.Address)
firstGoodTime.Interior.Color = RGB(100, 0, 0)
Set lastGoodTime = Range("B" & UBound(goodRow) - 1)
'MsgBox (lastGoodTime.Address)
lastGoodTime.Interior.Color = RGB(100, 0, 0)
end sub