Getting arry data in loop from outside

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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If the array goodRow contains the row nos for all the rows of 'good' data shouldn't you be looping through it at the end to do the formatting?
Code:
For I = LBound(goodRow) To UBound(goodRow)
    Set firstGoodTime = Range("B" & goodRow(I))
    firstGoodTime.Interior.Color = RGB(100,0,0)
Next I
 
Upvote 0
This would highlight all the good row but I only want the earliest(first) and the latest one so I can calculate the times between if that make sense
 
Upvote 0
Anyway after a night sleep, I figured out the LBound() and UBound() only give location not the value within so I have solved my own problem now by referring to the location those function give me.

Thanks for trying to help tho, @Norie
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top