Hi guys,
I'm having a big excel file with multiple sheets; some of them contain "Time interval" column with UNIX epoch time.
I'm running a macro to do the following:
-search thru all sheets and where it finds the "Time interval" column,
-applies the time conversion formula from UNIX to human time stamp, then
-deletes the UNIX time column and keeps only the human time
In sheet "General" $B20, I may have a GMT/UTC correction in minutes (e.q. -300 minutes > GMT -6hours).
If this cell (B20) is different than 0, can you please help me to modify the code by introducing a new column (let's say- "Local time") that adjusts the human time stamp with the GMT offset of -300 minutes?
Or, if much easier, just to update the formula with TIME function to add/subtract the offset of "General" sheet, B20, and add the output (human time stamp+GMT correction) in a single column.
Thank you in advance
The code:
Sub ConvertDate()
Dim i As Long
Dim wks As Worksheet
Dim rFind As Range
Dim rOut As Range
If Not Evaluate("ISREF(General!A1)") Then
Exit Sub
Else
For i = 2 To ActiveWorkbook.Sheets.Count
Set wks = Sheets(i)
With wks
Set rFind = .Cells.Find(What:="Time interval", LookIn:=xlFormulas, LookAt:=xlWhole, MatchCase:=False)
If Not rFind Is Nothing Then
.Columns(rFind.Column + 1).EntireColumn.Insert
Set rOut = Range(rFind, .Cells(Rows.Count, rFind.Column).End(xlUp)).Offset(, 1)
If rOut.Rows.Count > 1 Then
rOut.Cells(1) = "Time interval"
With rOut.Offset(1)
.NumberFormat = "dd/mm/yyyy hh:mm:ss"
.FormulaR1C1 = "=IF(RC[-1] = """", """", RC[-1]/86400 + DATE(1970,1,1) - DATE(1900,1,1) + 1)"
.Value2 = .Value2
.EntireColumn.AutoFit
.Offset(, -1).EntireColumn.Delete
End With
End If
End If
End With
Next i
End If
End Sub
Bookmarks