most
Board Regular
- Joined
- Feb 22, 2011
- Messages
- 107
- Office Version
- 365
- 2019
- Platform
- Windows
- Mobile
I'm stuck, i'm working on a macro which should consolidate some data.
See this printscreen.
The macro should produce one line for each date with an average, min and max of temperature and humidity.
This is as far as I have come, I manage to print a dictionary with the data, but I don't know how to calculate average, min and max of the dictionary.
See this printscreen.
The macro should produce one line for each date with an average, min and max of temperature and humidity.
This is as far as I have come, I manage to print a dictionary with the data, but I don't know how to calculate average, min and max of the dictionary.
Code:
Sub Consolidate()
Dim InDic As Object
Set InDic = CreateObject("Scripting.Dictionary")
Dim i As Integer
c_date = "2019-02-19" 'Left(ActiveCell.Value, 10)
With Sheets("Master")
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If (.Cells(i, 1) <> "") Then 'skip if date doesn't exist
If (Left(.Cells(i, 1), 10) = c_date) Then
InDic.Item(.Cells(i, 2).Value) = .Cells(i, 2).Value 'put temp1 into dict
InDic.Item(.Cells(i, 3).Value) = .Cells(i, 3).Value 'put temp2 into dict
InDic.Item(.Cells(i, 4).Value) = .Cells(i, 4).Value 'put humid into dict
Else
'nothing
End If
End If
Next i
'Average, max and min
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
dTemp1 = .Cells(i, 2)
dDate = Left(.Cells(i, 1), 10)
If dDate = c_date Then
Debug.Print dTemp1
'Do something magic
End If
Next i
End With
End Sub