Get hourly stats from array. Need some help please?

Dan_R

New Member
Joined
Jul 15, 2015
Messages
10
Hello,
I was hoping someone would be able to help me out with an excel problem I have.
I have a spreadsheet which contains data in one minute intervals in the following format:

ABC
7/16/2015 0:002.45.3
7/16/2015 0:012.24.1
7/16/2015 0:022.86.2
7/16/2015 0:032.45.4

<tbody>
</tbody>

<tbody>
</tbody>
etc. for 1400 odd records (24hrs)

What I need to end up with is for each hour, the maximum value in column C with the corresponding value in column B. This data then gets pasted into several other sheets. For example, the above data may result in:
ABC
7/16/2015 1:002.86.2
7/16/2015 2:004.19.5

<tbody>
</tbody>
etc. for 24 records.

I've put them into an array as follows;
Code:
Dim Array_1() As Variant
Dim r, i As Integer

r = WorksheetFunction.CountA(Worksheets(1).Columns(1))
    ReDim Array_1(r, 2)
    
For i = 1 To r
    Array_1(i, 0) = Range("A" & i + 2)
    Array_1(i, 1) = Range("B" & i + 2)
    Array_1(i, 2) = Range("C" & i + 2)
Next
But, I'm not sure what to do from there. Do I have to reDim this into 24 sub arrays to get the data for each hour or can I do it directly from the original array? I think I could work out how to do ReDim this using the row number but also, occasionally, a record will be missed (or sometimes duplicated) so that would displace the records from then on. It would be better to actually look at the times.

I know there not much to go on so far, but I'm hoping there's a simple way to do this and I can't seem to find anything.

Thanks in advance for any help.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
for, say, the 7th hour, do you want only the max for hours 1 to 7

if not - it is pretty easy
 
Upvote 0
Hang on...
I think I may have it, with a bit of help from a friend. I'll post what I've done here anyway if it works in case any one else finds it useful...
 
Upvote 0
Ok, I'm still working on it but think I'm making progress, if a bit slow an long winded. I'd like to hear your thoughts though if you have time?

No, for the first Hour I want stats for 00:00 to 01:00
for 2nd hour from 01:00 to 02:00 etc,
so for the 7th hour only for 06:00 to 07:00

Thanks

Sorry only just saw your post
 
Last edited:
Upvote 0
Try this based on your Data (Starting "A1"). Results start "G1"
Code:
[COLOR=Navy]Sub[/COLOR] MG19Jul14
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, nRng [COLOR=Navy]As[/COLOR] Range, Rw [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Dim[/COLOR] c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] oMax [COLOR=Navy]As[/COLOR] Double
[COLOR=Navy]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
ReDim ray(1 To Rng.Count, 1 To 3)
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    [COLOR=Navy]If[/COLOR] Not nRng [COLOR=Navy]Is[/COLOR] Nothing And Minute(Dn.Value) Mod 60 = 0 [COLOR=Navy]Then[/COLOR]
        c = c + 1
        oMax = Application.Max(nRng)
        Rw = Application.Match(oMax, nRng, 0)
        ray(c, 1) = nRng(Rw, -1): ray(c, 2) = nRng(Rw, 0): ray(c, 3) = nRng(Rw, 1)
        [COLOR=Navy]Set[/COLOR] nRng = Nothing
    [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]
    If[/COLOR] nRng [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
        [COLOR=Navy]Set[/COLOR] nRng = Dn.Offset(, 2)
    [COLOR=Navy]Else[/COLOR]
        [COLOR=Navy]Set[/COLOR] nRng = Union(nRng, Dn.Offset(, 2))
    [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]Next[/COLOR] Dn
Range("G1").Resize(c, 3) = ray
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Thanks,
It looks like a much neater solution than what I was working on, but I get a 'Type Mismatch' error at this line;
Code:
    If Not nRng Is Nothing And Minute(Dn.Value) Mod 60 = 0 Then
 
Upvote 0
Do your Date/times actually start in "A1" ?????? and are they actual "Dates/Times"
 
Upvote 0
Ahh, could be because the data starts in A3, not A1, that gives me some results, still not quite right but I'll keep working on it;

16/07/2015 00:222.45.5
16/07/2015 01:082.55.7
16/07/2015 02:062.63.8
16/07/2015 03:001.21.8
5.7
16/07/2015 04:331.74.2
5.7
16/07/2015 05:582.95.3
16/07/2015 06:472.88.5
16/07/2015 07:042.38.9
16/07/2015 08:562.39.5
16/07/2015 09:002.29.5
16/07/2015 10:462.78.8
16/07/2015 11:023.67.5
9.5
16/07/2015 12:599.313.8
16/07/2015 13:269.619.3
16/07/2015 14:517.518.3
16/07/2015 15:4710.220.7
16/07/2015 16:0710.622.8
16/07/2015 17:119.118.6
16/07/2015 18:421022.5
16/07/2015 19:169.930.3
16/07/2015 20:317.117.5
16/07/2015 21:087.817
16/07/2015 22:096.410.6

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0
I have a few blanks as well in the date/time group which I can't avoid, so I'll try cleaning them out first as well.
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,542
Members
449,169
Latest member
mm424

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