如何在Excel VBA中重复循环
我在Excel中有一张数据,其中包含数千小时内每5分钟一次的信息,因此每小时有12条数据。我写了一些vba代码,从第一个小时的数据中选择最大值,但我想知道
如何在所有其他时间重复这个。有人知道怎么做吗?这是我第一个小时的代码:
I have a sheet of data in Excel with information for every 5 minutes over thousands of hours, so there are 12 pieces of data for each hour. I have written some vba code that selects the maximum value from the data for the first hour but I want to know how to repeat this for all the other hours. Anyone know how to do this? Here is the code I have for the first hour:
在这里:
Sub MaxPerHour()
Dim m As Long
Application.ScreenUpdating = False
m =范围("A"& Rows.Count).End(xlUp).Row
使用范围("E2:E"& m)
.Formula =" = IF(A2 = MAX(OFFSET(A2,-MOD(ROW() - 2,12),0,12,1)),"是","","否" ;")"
$
'Value = .Value
结束与$
Application.ScreenUpdating = True
End Sub
Sub MaxPerHour()
Dim m As Long
Application.ScreenUpdating = False
m = Range("A" & Rows.Count).End(xlUp).Row
With Range("E2:E" & m)
.Formula = "=IF(A2=MAX(OFFSET(A2,-MOD(ROW()-2,12),0,12,1)),""Yes"",""No"")"
'Value = .Value
End With
Application.ScreenUpdating = True
End Sub