本文主要是介绍我是凑数王,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天客户让我算Category Credit Qual 的Breakdown。这几万条数据的,我怎么给他凑出来那个数。于是想到了之前一个凑数模板,在此基础上修改一下,就能用来抓住里面的各元素,再倒回去分析。特此贴一个裸版。
Public arr1Sub AvgCalculator()'To assign column K to one dimensional arrayarr1 = WorksheetFunction.Transpose(Range(Sheet1.Cells(2, 9), Sheet1.Cells(48, 9)).Value)'Better to use a bubble sort here.Dim arr2(1 To 5, 1 To 1)Dim AvgSum1 As DoubleAvgSum1 = 0k = 1Do While (AvgSum1 <> 43.995)AvgSum1 = 0For i = 1 To 5bbb = Random(47, 1)For h = 1 To 5 'Remove duplicate numbersDo While bbb = arr2(h, 1)bbb = Random(47, 1)LoopNext harr2(i, 1) = bbbAvgSum1 = AvgSum1 + arr1(bbb)Next iAvgSum1 = Round(AvgSum1 / 5, 3)LoopMsgBox AvgSum1MsgBox "You got it ... "MsgBox arr2(1, 1)MsgBox arr2(2, 1)MsgBox arr2(3, 1)MsgBox arr2(4, 1)MsgBox arr2(5, 1)End SubFunction Random(UpB, LoB)Random = Int((UpB - LoB + 1) * Rnd + LoB)End Function
这篇关于我是凑数王的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!