|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 鄂龙蒙 于 2018-7-29 22:38 编辑
请教:下面的代码怎么改,才能循环到结束?谢谢!若一行数据超过50时就一行为一段。
Sub 记录循环分段()
Dim arr, s, i, a, m, sa, br()
arr = [A1].CurrentRegion.Value
sa = 0: a = 2
For i = 2 To UBound(arr)
sa = sa + Cells(i, 2) * 1
If sa > 50 Then
s = i - 1
m = m + 1
ReDim Preserve br(1 To 3, 1 To m)
br(1, m) = a
br(2, m) = s
br(3, m) = sa - arr(i, 2)
Exit For
End If
Next
sa = 0: a = s + 1
For i = a To UBound(arr)
sa = sa + Cells(i, 2) * 1
If sa > 50 Then
s = i - 1
m = m + 1
ReDim Preserve br(1 To 3, 1 To m)
br(1, m) = a
br(2, m) = s
br(3, m) = sa - arr(i, 2)
Exit For
End If
Next
sa = 0: a = s + 1
For i = a To UBound(arr)
sa = sa + Cells(i, 2) * 1
If sa > 50 Then
s = i - 1
m = m + 1
ReDim Preserve br(1 To 3, 1 To m)
br(1, m) = a
br(2, m) = s
br(3, m) = sa - arr(i, 2)
Exit For
End If
Next
'。。。。。。。。。请教:下面如何循环到结束,谢谢
Range("E2:G10000").ClearContents
[E2].Resize(m, 3) = Application.Transpose(br)
End Sub
记录循环分段--每段不超过50.rar
(16.05 KB, 下载次数: 4)
|
|