|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。。。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$M$1" Then
arr = [e3:e102]
m = 0: n = 0
For i = UBound(arr) To 2 Step -1
If arr(i, 1) > 1 Then arr(i, 1) = 2
Next
For i = 1 To UBound(arr)
If arr(i, 1) <> Empty Then s = s & arr(i, 1): m = m + 1
Next
ReDim brr(1 To UBound(arr), 0)
For i = 1 To Len(s)
x = InStr(i, s, "1")
y = InStr(i, s, "2")
If x > y And y > 0 Or x < y And x > 0 Then
n = n + 1
brr(n, 0) = Abs(x - y)
i = Application.Max(x, y) - 1
ElseIf x > 0 And y = 0 Or y > 0 And x = 0 Then
n = n + 1
brr(n, 0) = m - Application.Max(x, y) + 1
i = UBound(arr)
End If
Next
Cells(100 - n + 1, "m").Resize(n) = brr
Beep
End If
Application.EnableEvents = True
End Sub
|
评分
-
2
查看全部评分
-
|