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.
 
Sorry, still can't do it,
Here's what I have using your code
Code:
Dim Rng As Range, Dn As Range, nRng As Range, Rw As Long
Dim c As Long, oMax As Double

'get rid of blank rows
   Columns("A:A").Select
   Selection.SpecialCells(xlCellTypeBlanks).Select
   Selection.EntireRow.Delete

Set Rng = Range(Range("A3"), Range("A" & Rows.Count).End(xlUp))
ReDim ray(1 To Rng.Count, 1 To 3)
For Each Dn In Rng
    If Not nRng Is Nothing And Minute(Dn.Value) Mod 60 = 0 Then
        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)
        Set nRng = Nothing
    End If


    If nRng Is Nothing Then
        Set nRng = Dn.Offset(, 2)
    Else
        Set nRng = Union(nRng, Dn.Offset(, 2))
    End If
Next Dn
Range("G1").Resize(c, 3) = ray

I'm not very good at this so I don't fuly understand our code, but these are the results I get, starting in G1;
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:401.63.3
16/07/2015 04:331.74.2
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
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>


Any suggestions?
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Here's an alternative to allow for Blank rows in Data.
Your Data assumed to start "A3", Results Start "G1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG19Jul44
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Temp [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
    [COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A3"), 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 Dn.Value = "" [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] Not Rng(1) = Dn.Value And Minute(Dn.Value) Mod 60 = 0 [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        ray(c, 1) = Temp: ray(c, 2) = Temp.Offset(, 1).Value: ray(c, 3) = Temp.Offset(, 2).Value
        [COLOR="Navy"]Set[/COLOR] Temp = Nothing
    [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]If[/COLOR] Temp [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] Temp = Dn
        [COLOR="Navy"]If[/COLOR] Dn.Offset(, 2) > Temp.Offset(, 2) [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] Temp = Dn
    [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
 
Upvote 0
Ahh, thank you Mick, got it working, I am a bit slow after all...
The original version you sent me does work when I set it to look at data starting in A3, just not quite as I was expecting. You' ve asked it to record the actual time of the max, I was expecting the max in the hour i.e. data in G would be for 01:00, 02:00 etc. That's fine though, I can use that anyway.
There was one other problem, the data only went up to 23:59 so I didn't get the last hour and I only 23 rows, but I added a extra row on the end using a DateAdd with a blank record of 00:00 for the following day and now it works fine.

Thanks so much for helping me out with that, it would have taken me ages to do it the way I was trying.
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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