here is a screenshot of my dataI have a set of measurements. Their related timestamps are in text format, like this: 12/23/2021 2:00:00 AM. My goal is to calculate a daily average of my measurements. I have this code but it stops in consolidate step. Does anyone know how to fix it:
Sub consolidate()
Dim folderPath As String
Dim filename As String
Dim wkb As Workbook
folderPath = "F:\analysis\12hourly\"
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wkb = Workbooks.Open(folderPath & filename) 'Open all files in directory
wkb.Activate
Rows("1:1").Select
Selection.Delete Shift:=xlUp 'Delete first row
Dim Lastrow As Integer
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Lastrow2 = Range("B" & Rows.Count).End(xlUp).Row
Dim D, E
D = Mid("A3:Lastrow", 1, 10) 'Remove hour & minute
Dim wkbr As Workbook
Set wkbr = Workbooks.Add
Dim rng As Range
Set rng = wkrb.Sheets("Sheet1").Cells(1, 1)
wkb.Activate
Dim ConsolidateRangeArray As Variant 'Daily average
ConsolidateRangeArray = Array(D, "B3:Lastrow2")
rng.consolidate _
Sources:=ConsolidateRangeArray, _
Function:=xlAverage, TopRow:=False, LeftColumn:=True, CreateLinks:=False
Dim wkbpath As String
Dim wkbname As String
wkb.Activate
wkbpath = "F:\analysis\2daily\" 'Save result in folder daily
wkbname = ActiveWorkbook.Name
ActiveWorkbook.SaveAs filename:= _
wkbpath & wkbname & ".xlsx", FileFormat:=xlCSVUTF8 _
, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = False
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub