我想我得到了它的工作。请查看下面的代码。它应该安装在您想要结果的工作表的代码表中。
Private Sub Worksheet_Change(ByVal Target As Range)
' Variatus @STO 07 Apr 2020
Dim Arr As Variant
Dim Rng As Range
Dim Result As String
Dim R As Long, Ra As Long
With Target
If .Cells.CountLarge > 1 Then Exit Sub
Set Rng = Range(Cells(2, 2), Cells(Rows.Count, 2).End(xlUp).Offset(1))
If Not Application.Intersect(Target, Rng) Is Nothing Then
Arr = Range(Cells(1, 1), Cells(Rows.Count, 2).End(xlUp).Offset(1)).Value
For R = 2 To Rng.Rows.Count
If Result = "" Then Result = ResultString(Result, R, Arr)
Arr(R, 1) = Result
Cells(R, 1).Value = Result
If R < UBound(Arr) Then
If Arr(R + 1, 2) = False Then
Result = ResultString(Result, R + 1, Arr)
End If
End If
Next R
End If
End With
End Sub
Private Function ResultString(ByVal Seed As Variant, _
ByVal R As Long, _
Arr As Variant) As String
' Variatus @STO 07 Apr 2020
Const Start As Integer = 166
Dim Fun As String
Dim Sp() As String
Dim i As Integer
On Error Resume Next
Sp = Split(Seed, ",")
Seed = Val(Sp(UBound(Sp))) + 1
If Err.Number Then Seed = Start
Fun = Seed
On Error GoTo 0
Do While (R + i) < UBound(Arr)
i = i + 1
If Arr(R + i, 2) = False Then Exit Do
Fun = Fun & ", " & CStr(Val(Seed) + i)
Loop
ResultString = Fun
End Function
事件过程响应 B 列中的更改,并将根据在那里找到的条目 - True 和 False(或空白)构建 A 列。每次更改都必须重建整个列。观察包含起始编号的Const Start As Integer = 166。