Time range between specific value

sanrama

New Member
Joined
May 2, 2015
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I want to find time range between specific rang of value
Please refer below table

Downtime - Chlorine flow.xlsx
BCDEF
2Time01-Jan02-Jan03-Jan
30:00193901500
41:00194600
52:0019461500
63:00194512000
74:00195119640
85:00195419661839
96:00194319421840
107:00193619391839
118:00193501838
129:00194300
1310:00194800
1411:00194000
1512:00150001844
1613:0010002501847
1714:002002801851
1815:0010019461849
1916:00019501841
2017:00019420
2118:00019410
2219:00019580
2320:0007001836
2421:002002001835
2522:0040001840
2623:00193901845
27
28Required Value
29
30Time at 1st Instance when value goes below 300From 14:000:001:00
31Time at 1st Instance when value goes ablove 300To21:002:004:00
32
33Time at 2nd Instance when value goes below 300From 8:009:00
34Time at 2ndInstance when value goes ablove 300To14:0011:00
35
36Time at 3rd Instance when value goes below 300From 20:0017:00
37Time at 3rd Instance when value goes ablove 300To23:0019:00
38
39Time at 4th Instance when value goes below 300From
40Time at 4th Instance when value goes ablove 300To
December
Cell Formulas
RangeFormula
C3C3=C26+1/24
C10:C26,C4:C8C4=C3+1/24
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D3:F26Cell Value<900textNO
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If you are open to a user-defined function (UDF), this code was successful for me. Put this code into a VBA Module.
VBA Code:
Function GetTime(Target As Range, Instance As Integer, IsBelow As Boolean)
    Dim HourCells As Range
    Dim HourCell As Range
    Dim iInstance As Integer
    Dim i As Integer
    Dim j As Integer
    Dim Below As Range
    Dim Above As Range
    
    iInstance = 1
    Set HourCells = Range(Cells(3, Target.Column), Cells(26, Target.Column))
    Do
        Set Below = Nothing
        Set Above = Nothing
        For i = iInstance To 24
            If CInt(HourCells(i)) <= 300 Then
                Set Below = HourCells(i)
                If i = 24 Then
                    If CInt(HourCells(1).Offset(0, 1)) >= 300 Then
                        Set Above = HourCells(24)
                    End If
                    Instance = Instance - 1
                    Exit Do
                Else
                    For j = i + 1 To 24
                        If CInt(HourCells(j)) >= 300 Then
                            Set Above = HourCells(j - 1)
                            iInstance = j
                            Exit For
                        End If
                    Next j
                    If j = 25 Then
                        If CInt(HourCells(1).Offset(0, 1)) >= 300 Then
                            Set Above = HourCells(24)
                        End If
                        Instance = Instance - 1
                        Exit Do
                    End If
                End If
                Exit For
            End If
        Next
        Instance = Instance - 1
    Loop While Instance > 0
    GetTime = ""
    If Instance = 0 Then
        If IsBelow Then
            If Not Below Is Nothing Then
                GetTime = Cells(Below.Row, 3).Value
            End If
        Else
            If Not Above Is Nothing Then
                GetTime = Cells(Above.Row, 3).Value
            End If
        End If
    End If
End Function
If you want the sheet to automatically update the UDFs, you can put this into the Sheet code:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.CalculateFull
End Sub
GetTime.xlsm
BCDEF
2Time01-Jan02-Jan03-Jan
30:00193901500
41:00194600
52:0019461500
63:00194512000
74:00195119640
85:00195419661839
96:00194319421840
107:00193619391839
118:00193501838
129:00194300
1310:00194800
1411:00194000
1512:00150001844
1613:0010002501847
1714:002002801851
1815:0010019461849
1916:00019501841
2017:00019420
2118:00019410
2219:00019580
2320:0007001836
2421:002002001835
2522:0040001840
2623:00194801845
27
28Required Value
29
30Time at 1st Instance when value goes below 300From 14:000:001:00
31Time at 1st Instance when value goes ablove 300To21:002:004:00
32
33Time at 2nd Instance when value goes below 300From  8:009:00
34Time at 2ndInstance when value goes ablove 300To 14:0011:00
35
36Time at 3rd Instance when value goes below 300From  21:0017:00
37Time at 3rd Instance when value goes ablove 300To 23:0019:00
38
39Time at 4th Instance when value goes below 300From    
40Time at 4th Instance when value goes ablove 300To   
Sheet1 (2)
Cell Formulas
RangeFormula
C4:C26C4=C3+1/24
D30:F30D30=GetTime(D30,1,TRUE)
D31:F31D31=GetTime(D31,1,FALSE)
D33:F33D33=GetTime(D33,2,TRUE)
D34:F34D34=GetTime(D34,2,FALSE)
D36:F36D36=GetTime(D36,3,TRUE)
D37:F37D37=GetTime(D37,3,FALSE)
D39:F39D39=GetTime(D39,4,TRUE)
D40:F40D40=GetTime(D40,4,FALSE)
 
Upvote 0
Thanks shknbk2
I need to use excel formula instead of VBA.

Can we solve by excel formula ?
 
Upvote 0
Possibly, but someone else will have to provide it.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

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