|
本帖最后由 fzxba 于 2022-12-13 19:19 编辑
Sub test1() '练习 参与
Dim vData, vResult(1 To 18), vTemp(), Dict As Object
Dim vPos(), vNum(0 To 30) As Long, x As Integer, y As Long
Dim i As Long, j As Long, p As Long, n As Long, s As String
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate
j = UBound(vResult)
vData = Range("C11", Cells(Rows.Count, "C").End(xlUp)).Value
ReDim vTemp(-Int(-UBound(vData) / j / 2), UBound(vNum))
For n = LBound(vTemp, 2) To UBound(vTemp, 2)
vTemp(0, n) = n
Next
ReDim vPos(1 To j)
For x = LBound(vResult) To j
vPos(x) = vNum
vResult(x) = vTemp
Next
ReDim vTemp(n * j, 0)
Set Dict = CreateObject("Scripting.Dictionary")
For y = 1 To UBound(vData) Step j * 2
Dict.RemoveAll
For i = y + j To y + j * 2 - 1
If Not Dict.Exists(vData(i, 1)) Then Dict.Add vData(i, 1), vbNullString
Next
For i = y To y + j - 1
p = (i - 1) Mod (j * 2) + 1
For n = LBound(vNum) To UBound(vNum)
vPos(p)(n) = vPos(p)(n) + 1
x = CInt(Dict.Exists(vData(i, 1) + n))
If x Then
If vPos(p)(n) > 1 Then
If vResult(p)(vPos(p)(n) - 1, n) Then vPos(p)(n) = vPos(p)(n) - 1
End If
End If
vResult(p)(vPos(p)(n), n) = vResult(p)(vPos(p)(n), n) - x
Next
Next
Next
y = 0
For x = LBound(vResult) To j
s = Format(x, "00")
With Worksheets(s).Range("H10")
.CurrentRegion.ClearContents
.Resize(UBound(vResult(x)) + 1, UBound(vResult(x), 2) + 1) = vResult(x)
End With
s = "第" & s & "位加 [n] 连续累计最后是:"
For n = LBound(vNum) To UBound(vNum)
vTemp(y, 0) = Replace(s, "[n]", n) & vResult(x)(vPos(x)(n), n)
y = y + 1
Next
Next
With Worksheets("结果表").Range("B1")
.Resize(Rows.Count).ClearContents
.Resize(y) = vTemp
End With
Set Dict = Nothing
Application.ScreenUpdating = True
Beep
End Sub
'评价侮辱了代码
|
评分
-
1
查看全部评分
-
|