Private Sub Command_Click() 'Column_1相等的情况下,Column_2相邻行相减
Row = 2 '设置开始行值
Column_1 = 1 '设置需要相减的列值
Column_2 = 3 '需要将结果数据放置的列值
Do
t = Cells(Row, Column_1)
v = Cells(Row + 1, Column_1)
If v = "" Then Exit Do
If t = v Then
Cells(Row, Column_2) = Cells(Row + 1, 2) - Cells(Row, 2)
Else: End If
Row = Row + 1
Loop
End Sub
Private Sub CommandButton1_Click() '相邻块取最小值
i = 2 '设置开始行值
Do
j = 0 '设置块
t = Cells(i, 11)
Do
v = Cells(i + j + 1, 11)
If v = 0 Then Exit Do
If t < v Then '取最小值
Cells(i, 12) = t
ElseIf t > v Then
Cells(i, 12) = v
ElseIf t = v Then
Cells(i, 12) = t
End If
t = Cells(i, 12)
j = j + 1
Loop
If v = "" Then Exit Do '遇到空行即结束
i = i + j + 1 '下一个块行值
Loop
End Sub
Private Sub CommandButton2_Click() '相隔60秒计数,注意列值为时间
i = 2 '设置开始行号
Do
j = 0 '设置块
t = Cells(i, 1) '第i个比较块,列值为1
Do
V = Cells(i + j + 1, 1)
If V = "" Then Exit Do
If V - t > 60 / 24 / 3600 Then
j = j + 1
Exit Do
Else: End If
j = j + 1
Loop
Cells(i, 3) = j '结果放在第3列
If V = "" Then
Cells(i, 3) = j + 1 '最后一个块自动加1
Exit Do
Else: End If
i = i + j '下一个块行值
Loop
End Sub
Private Sub CommandButton3_Click() '每隔60秒计数, 列值为时间, 放在第一列
i = 2 '设置开始行号
k = 0
m = Cells(i, 1)
Do
j = 0 '设置块
t = m + k * 60 / 24 / 3600 '第i个比较块,列值为1
Do
V = Cells(i + j + 1, 1)
If V = "" Then Exit Do
If V - t > 60 / 24 / 3600 Then
j = j + 1
Exit Do
Else: End If
j = j + 1
Loop
Cells(i, 3) = j '结果放在第3列
If V = "" Then
Cells(i, 3) = j + 1 '最后一个块自动加1
Exit Do
Else: End If
k = k + 1
i = i + j '下一个块行值
Loop
End Sub