我试图让代码从输入框中读取一个值,这是所需的投资金额,即。3000. 然后读取以特定价格可用的 btc 数量的列表(40 行长),并连续总结这些总美元金额(数量*价格),直到添加下一行的点大于所需的投资金额(即,我正在尝试以最便宜的方式获得一堆 btc)。
然后我会写一点来弥补下一行的其余值,因为它显然不会完美地达到,但我似乎无法让这一点工作。当我执行代码时,我得到了一些没有多大意义的奇怪结果。我已经放了一个表格的例子,所以你可以看到我正在使用什么(第一个价格 94.25 是 B3/ActiveCell) 这可能非常微不足道,但我以前从未做过任何这些事情。感谢您抽出宝贵时间,我希望我已经足够清楚地概述了它。
Sub Projected()
Dim InvestValue As Single
Dim SumBTCE As Single
Dim Sumup As Single
Dim NumBTC As Single
Dim Count As Integer
InvestValue = InputBox("Input investment amount:")
NumBTC = 0
Sumup = 0
ActiveWorkbook.Sheets("BTC-E Data").Cells(3, 2).Select
Do Until (Sumup + (ActiveCell.Offset(Count, 0).Value * ActiveCell.Offset(Count, 1).Value)) >= InvestValue
For Count = 1 To 40
Sumup = Sumup + ActiveCell.Offset(Count - 1, 0).Value * ActiveCell.Offset(Count - 1, 1).Value
NumBTC = NumBTC + ActiveCell.Offset(0, 1).Value
Next Count
Loop
MsgBox NumBTC
MsgBox Sumup
End Sub
price BTC USD
94.25 0.1 9.425
94.439 0.34583324 32.66014535
94.44 2 188.88
94.443 0.011 1.038873
94.444 0.4 37.7776
94.493 0.025 2.362325
94.5 0.1 9.45
94.55 0.1 9.455
94.6 0.1 9.46
94.601 0.5 47.3005
94.648 0.0112 1.0600576
94.649 4.12801098 390.7121112
94.65 35.75926753 3384.614672
94.664 2.128011 201.4460333
94.665 3.5 331.3275
94.679 0.1395 13.2077205
94.68 0.15 14.202
94.689 2.128011 201.4992336
94.69 18.73708352 1774.214439
94.698 0.010978 1.03959464
94.699 0.093 8.807007
94.7 0.1 9.47
94.704 0.025 2.3676
94.736 0.0837 7.9294032
94.737 0.09 8.52633
94.749 2.128011 201.6269142
94.75 20.1 1904.475
94.755 0.1 9.4755
94.8 0.1 9.48
94.801 0.03758691 3.56327665
94.81 5.7236763 542.66175
94.829 0.15 14.22435
94.84 0.20095058 19.058153
94.85 0.1 9.485
94.87 0.01 0.9487
94.879 0.401 38.046479
94.88 0.01 0.9488
94.887 0.40930425 38.83765236
94.89 0.01 0.9489
94.9 0.30106377 28.57095176