|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 zhjlgaojuan 于 2018-7-16 16:04 编辑
Sub test(SourceNum As Double, SplitCount As Long)
Dim TargetArr(), TmpSum#, AverageNum#
ReDim TargetArr(1 To SplitCount, 1 To 1)
AverageNum = SourceNum / SplitCount
TmpSum = 0
TargetArr(1, 1) = AverageNum * WorksheetFunction.RandBetween(9900, 10100) / 10000
TmpSum = TmpSum + TargetArr(1, 1)
For i = 2 To SplitCount - 1
If (SourceNum - TmpSum) / (SplitCount - i + 1) > AverageNum Then
TargetArr(i, 1) = AverageNum * (1 + WorksheetFunction.RandBetween(0, 100) / 10000)
Else
TargetArr(i, 1) = AverageNum * (1 - WorksheetFunction.RandBetween(0, 100) / 10000)
End If
TmpSum = TmpSum + TargetArr(i, 1)
Next
TargetArr(SplitCount, 1) = SourceNum - TmpSum
[f2].Resize(SplitCount, 1) = TargetArr
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$F$1" Then [g1].Select: test [a2], [b2]
End Sub
|
|