Macro to consolidate some data

most

Board Regular
Joined
Feb 22, 2011
Messages
107
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. 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.


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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
No, will have about 45k of lines per year and I will save data for several of years. Need to consolidate them.
 
Upvote 0
No, will have about 45k of lines per year and I will save data for several of years. Need to consolidate them.
As Alan said, this is just the kind of thing a pivot table is good for, consolidating. You will have 45k lines or raw data, the pivot table would allow you to quickly get the 365 daily statistics you'll need for each year. Far better than adding rows to your raw data table. Were you planning to put the statistics at the bottom of each year's data or below all years?
 
Upvote 0
Hi Must, I wonder How have you suceedeed to put a screenshot ? I thought it was impossible.

I would like to do the same in my threads, it could be useful to be better understood
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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