请问如何修改如下VBA代码计算出大于>0,小于<10的连续个数?
Sub小于10的连续个数()Dimaa(60000)SetRng=Selection(1)a=Rng.Rowb=Rng.ColumnSetRng=Selection(Se...
Sub 小于10的连续个数()
Dim aa(60000)
Set Rng = Selection(1)
a = Rng.Row
b = Rng.Column
Set Rng = Selection(Selection.Count)
c = Rng.Row
For i = a To c + 1
If Cells(i, b) < 10 Then
x = x + 1
Else
If x <> 0 Then
aa(K) = x
K = K + 1
End If
x = 0
End If
Next i
ii = 0
For j = 60000 To 0 Step -1
If aa(j) <> 0 Then
Cells(c - ii, b + 1) = aa(j)
ii = ii + 1
End If
Next j
End Sub
, 展开
Dim aa(60000)
Set Rng = Selection(1)
a = Rng.Row
b = Rng.Column
Set Rng = Selection(Selection.Count)
c = Rng.Row
For i = a To c + 1
If Cells(i, b) < 10 Then
x = x + 1
Else
If x <> 0 Then
aa(K) = x
K = K + 1
End If
x = 0
End If
Next i
ii = 0
For j = 60000 To 0 Step -1
If aa(j) <> 0 Then
Cells(c - ii, b + 1) = aa(j)
ii = ii + 1
End If
Next j
End Sub
, 展开
展开全部
选中你的数据区,然后执行代码
Sub test()
Dim Arr, i As Integer, j As Integer
Arr = Selection: j = 0
For i = 1 To UBound(Arr, 1)
If Arr(i, 1) > 0 And Arr(i, 1) < 10 Then
j = j + 1: Arr(i, 1) = j
Else
j = 0: Arr(i, 1) = ""
End If
Next
Selection.Offset(0, 1) = Arr
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询