Excel VBA-如果存在值>;x、 加在一起,加上一句警告

Excel VBA-如果存在值>;x、 加在一起,加上一句警告,vba,excel,Vba,Excel,上周,我得到了以下代码的帮助:搜索一个表中大于91分钟的时间值,忽略第一个实例,然后在一个运行总数中对后续实例求和。我需要调整代码,以便如果第一个实例大于95分钟,忽略“ignorethefirstinstance”语句并将其相加 目前的代码如下: Dim ttlBTimes As Variant Dim ttlBThrshldTime As Double Dim ttlBSumResults() As Double Dim ttlBResultIndex As Long Dim ttlBi A

上周,我得到了以下代码的帮助:搜索一个表中大于91分钟的时间值,忽略第一个实例,然后在一个运行总数中对后续实例求和。我需要调整代码,以便如果第一个实例大于95分钟,忽略“ignorethefirstinstance”语句并将其相加

目前的代码如下:

Dim ttlBTimes As Variant
Dim ttlBThrshldTime As Double
Dim ttlBSumResults() As Double
Dim ttlBResultIndex As Long
Dim ttlBi As Long, ttlBj As Long
Dim ttlBFirst As Boolean

ttlBThrshldTime = TimeValue("01:31:00")
ttlBTimes = ActiveSheet.Range("B3:F9").Value
ReDim ttlBSumResults(1 To UBound(ttlBTimes, 1) - LBound(ttlBTimes, 1) + 1, 1 To 1)
For ttlBi = LBound(ttlBTimes, 1) To UBound(ttlBTimes, 1)
    ttlBResultIndex = ttlBResultIndex + 1
    ttlBFirst = True
    For ttlBj = LBound(ttlBTimes, 2) To UBound(ttlBTimes, 2)
        If ttlBTimes(ttlBi, ttlBj) > ttlBThrshldTime Then
            If ttlBFirst Then
                ttlBFirst = False
            Else
                ttlBSumResults(ttlBResultIndex, 1) = ttlBSumResults(ttlBResultIndex, 1) + ttlBTimes(ttlBi, ttlBj) - ttlBThrshldTime
            End If
        End If
    Next ttlBj
Next ttlBi
ActiveSheet.Range("G3").Resize(UBound(ttlBSumResults, 1)).Value = ttlBSumResults
试试这个,95是01:35

Dim ttlBTimes As Variant
Dim ttlBThrshldTime As Double
Dim ttlBSumResults() As Double
Dim ttlBResultIndex As Long
Dim ttlBi As Long, ttlBj As Long
Dim ttlBFirst As Boolean

ttlBThrshldTime = TimeValue("01:35:00")
ttlBTimes = ActiveSheet.Range("B3:F9").Value
ReDim ttlBSumResults(1 To UBound(ttlBTimes, 1) - LBound(ttlBTimes, 1) + 1, 1 To 1)
For ttlBi = LBound(ttlBTimes, 1) To UBound(ttlBTimes, 1)
    ttlBResultIndex = ttlBResultIndex + 1
    For ttlBj = LBound(ttlBTimes, 2) To UBound(ttlBTimes, 2)
        If ttlBTimes(ttlBi, ttlBj) > ttlBThrshldTime Then
                ttlBSumResults(ttlBResultIndex, 1) = ttlBSumResults(ttlBResultIndex, 1) + ttlBTimes(ttlBi, ttlBj) - ttlBThrshldTime
        End If
    Next ttlBj
Next ttlBi
ActiveSheet.Range("G3").Resize(UBound(ttlBSumResults, 1)).Value = ttlBSumResults
excel vba excel-vba

你不使用公式有什么原因吗?你是什么意思?我正在使用上面的VBA脚本,我只需要稍微编辑一下。类似这样的
=SUMIF($a$1:$a$11,“>=50”,$B$1:$B$11)-索引($B$1:$B$11,MATCH(50,$a$1:$a$11,0))
这看起来是50或更多,忽略第一个实例,你可以调整。抱歉@Nathan_Sav我需要VBA格式的这个。所以使用
工作表函数
有时我们可以过度使用excel的代码为我们做得很好。甚至
ActiveSheet.Range(“G3”).Resize().formula=“=SUMIF($A$1:$A$11,”>=50),$B$1:$B$11)-索引($B$1:$B$11,匹配(‌​50,$A$1:$A$11,0”)“
其中
工作表函数.COUNTIF
将帮助您导出X,可能是1或2行代码。但是,我是否正确,这样可以有效地消除91到95分钟的范围?我需要代码仍然计算该范围内的实例(抛出第一个实例,然后计算后续实例),您要求忽略代码所做的“忽略…”。如果您想重新激活“忽略…”只需返回初始代码并将01:31替换为01:35Correct;如果值超过01:35,则忽略“忽略”。否则,处理“忽略”。我正在努力理解你的代码,如果它已经理解了,我道歉。