find the max among a range of cells and repeat the search 365 times

AmandaSS

Board Regular
Joined
Jan 7, 2014
Messages
133
Hallo,

I have 8760 rows and one column with one value for each row.

row1
10
row2
23
row3
66
...
...
row8760
39

<tbody>
</tbody>

I need to check every 24 row what is the max value.
Can someone help?

Thanks
Amanda
 
Hi AmandaSS - Sorry I didn't see the previous posts before I developed this VBA macro. In column C it numbers 1-365 and in column D it lists the corresponding Max in the group of 24.

Hope you find it helpful.

Code:
Sub AmandaSS_Max_by_24rows()
Dim i, x As Integer
Dim MaxVal As Long
i = 1
x = 1
While i < 8761
    Set WorkRange = Range(Cells(i, 1), Cells(i + 23, 1))
    MaxVal = Application.WorksheetFunction.Max(WorkRange)
    Cells(x, 4).value = MaxVal
    Cells(x, 3).value = x
    i = i + 24
    x = x + 1
    Wend
End Sub
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi AmandaSS - Try the code:

Code:
Sub AmandaSS_Max_by_24rows()
Dim i, x As Integer
Dim MaxVal As Long
i = 1
x = 1
While i < 8761
    Set WorkRange = Range(Cells(i, 1), Cells(i + 23, 1))
    MaxVal = Application.WorksheetFunction.Max(WorkRange)
    Cells(x, 4).value = MaxVal
    Cells(x, 3).value = x
    i = i + 24
    x = x + 1
    Wend
End Sub
 
Upvote 0
Thanks Goesr, that looks fancy :)


how would the formula change if I wanted to calculate the mean of each 24 data?
can i still use a formula or do I have to go with VBA?

thanks,
Amanda
 
Upvote 0

Forum statistics

Threads
1,216,796
Messages
6,132,742
Members
449,756
Latest member
AdkinsP

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