Hi,
I have two columns: a date/time column A (dd/mm/yyyy hh:nn:ss) and a values column D.
I want to take a specific value in the column D and the corresponding date/time in column A.
After subtracting a time in minutes from that date/time, I want to check if exist a cell containing that resulting date/time in the
first column in order to get its row number.
The code seems to work fine only for some "mins" values,
e.g. mins=19 works,
mins=20 doesn't work.
Hope someone can help me with this.
Thank you
I have two columns: a date/time column A (dd/mm/yyyy hh:nn:ss) and a values column D.
I want to take a specific value in the column D and the corresponding date/time in column A.
After subtracting a time in minutes from that date/time, I want to check if exist a cell containing that resulting date/time in the
first column in order to get its row number.
The code seems to work fine only for some "mins" values,
e.g. mins=19 works,
mins=20 doesn't work.
Hope someone can help me with this.
Thank you
VBA Code:
Sub calc()
Dim rng As Range
Dim ran As Range
Dim maxT As Double
Dim line As Double
Dim roundown As Double
Set rng = Sheets(5).Range("D1:D1000")
maxT = Application.WorksheetFunction.Max(rng)
line = rng.Find(maxT, , xlValues).Row
roundown = Application.WorksheetFunction.RoundDown(maxT, 0)
Dim fin As Integer
Set ran = Sheets(5).Range("D" & line, "D" & line + 100)
For Each cell In ran
If cell.Value < roundown Then
fin = cell.Row - 1
Sheets(5).Range("A" & fin).EntireRow.Interior.ColorIndex = 6
Exit For
End If
Next
Dim dt1 As Date
Dim dt2 As Date
Dim mins As Integer
mins = Sheets(1).Range("E6").Value
dt1 = CDate(Sheets(5).Range("A" & fin))
dt2 = DateAdd("n", -mins, dt1)
With Worksheets(5)
Dim intv As Range
Set intv = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
For Each cell In intv
If cell = dt2 Then
MsgBox cell
Exit For
End If
Next
End With
End Sub