如何在Excel VBA中重复循环 [英] How to repeat a loop in Excel VBA

查看:305
本文介绍了如何在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


这篇关于如何在Excel VBA中重复循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆