当我单步执行代码时,当最后一个条件与else语句一起满足时,if会跳过结尾。与第一次检查一样,它必须检查所有条件,编译器或知道答案的东西,因此值得更改上半部分以与下半部分相同的方式运行。这段代码每天将运行4到5千次,但是不确定else语句的运行速度要快多少。
只需跨过代码并注意到正在发生的事情。
If WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T10TestDigit Then
LoopAddress = ActiveCell.Address
'OddQnt = ActiveCell
OddPrc = ActiveCell.Offset(0, 1)
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BU1").Activate
'Forgot Spread
If HowFar = "yes" Then OddPrc = OddPrc - Jump
If AmtOfTrds >= 1 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T1OffSet), Rnd - 1) + T1TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T1OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 2 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T2OffSet), Rnd - 1) + T2TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T2OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 3 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T3OffSet), Rnd - 1) + T3TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T3OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 4 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T4OffSet), Rnd - 1) + T4TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T4OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 5 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T5OffSet), Rnd - 1) + T5TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T5OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 6 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T6OffSet), Rnd - 1) + T6TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T6OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 7 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T7OffSet), Rnd - 1) + T7TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T7OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 8 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T8OffSet), Rnd - 1) + T8TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T8OffSet
Range("BT1") = Range("BT1") + 1
End If
If AmtOfTrds >= 9 Then
ActiveCell.Offset(Range("BT1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc - T9OffSet), Rnd - 1) + T9TestDigit
ActiveCell.Offset(Range("BT1"), 1) = OddPrc - T9OffSet
Range("BT1") = Range("BT1") + 1
End If
Range(LoopAddress).Select
'Else it is a buy and do the oppisite
Else
Range("BQ1").Activate
'Forgot Spread
If HowFar = "yes" Then OddPrc = OddPrc + Jump
If AmtOfTrds >= 1 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T1OffSet), Rnd - 1) + T1TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T1OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 2 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T2OffSet), Rnd - 1) + T2TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T2OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 3 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T3OffSet), Rnd - 1) + T3TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T3OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 4 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T4OffSet), Rnd - 1) + T4TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T4OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 5 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T5OffSet), Rnd - 1) + T5TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T5OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 6 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T6OffSet), Rnd - 1) + T6TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T6OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 7 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T7OffSet), Rnd - 1) + T7TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T7OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 8 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T8OffSet), Rnd - 1) + T8TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T8OffSet
Range("BP1") = Range("BP1") + 1
End If
If AmtOfTrds >= 9 Then
ActiveCell.Offset(Range("BP1"), 0) = WorksheetFunction.RoundDown(TrdAmt / (OddPrc + T9OffSet), Rnd - 1) + T9TestDigit
ActiveCell.Offset(Range("BP1"), 1) = OddPrc + T9OffSet
Range("BP1") = Range("BP1") + 1
End If
Range(LoopAddress).Select
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T1TestDigit Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG2") = Range("BG2") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T1OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T1Buy, Rnd - 1) + T1TestDigit
End If
Else
Range("BF2") = Range("BF2") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T1OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T1Sell, Rnd - 1) + T1TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T2TestDigit _
And NumOfActiveTrades >= 2 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG3") = Range("BG3") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T2OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T2Buy, Rnd - 1) + T2TestDigit
End If
Else
Range("BF3") = Range("BF3") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T2OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T2Sell, Rnd - 1) + T2TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T3TestDigit _
And NumOfActiveTrades >= 3 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG4") = Range("BG4") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T3OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T3Buy, Rnd - 1) + T3TestDigit
End If
Else
Range("BF4") = Range("BF4") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T3OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T3Sell, Rnd - 1) + T3TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T4TestDigit _
And NumOfActiveTrades >= 4 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG5") = Range("BG5") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T4OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T4Buy, Rnd - 1) + T4TestDigit
End If
Else
Range("BF5") = Range("BF5") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T4OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T4Sell, Rnd - 1) + T4TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T5TestDigit _
And NumOfActiveTrades >= 5 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG6") = Range("BG6") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T5OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T5Buy, Rnd - 1) + T5TestDigit
End If
Else
Range("BF6") = Range("BF6") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T5OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T5Sell, Rnd - 1) + T5TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T6TestDigit _
And NumOfActiveTrades >= 6 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG7") = Range("BG7") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T6OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T6Buy, Rnd - 1) + T6TestDigit
End If
Else
Range("BF7") = Range("BF7") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T6OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T6Sell, Rnd - 1) + T6TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T7TestDigit _
And NumOfActiveTrades >= 7 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG8") = Range("BG8") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T7OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T7Buy, Rnd - 1) + T7TestDigit
End If
Else
Range("BF8") = Range("BF8") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T7OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T7Sell, Rnd - 1) + T7TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T8TestDigit _
And NumOfActiveTrades >= 8 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG9") = Range("BG9") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T8OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T8Buy, Rnd - 1) + T8TestDigit
End If
Else
Range("BF9") = Range("BF9") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T8OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T8Sell, Rnd - 1) + T8TestDigit
End If
End If
ElseIf WorksheetFunction.Round(ActiveCell - WorksheetFunction.RoundDown(ActiveCell, Rnd - 1), Rnd) = T9TestDigit _
And NumOfActiveTrades >= 9 Then
If ActiveCell.Offset(0, 3) = "SELL" Then
Range("BG10") = Range("BG10") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) - T9OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T9Buy, Rnd - 1) + T9TestDigit
End If
Else
Range("BF10") = Range("BF10") + 1
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 1) + T9OffSet
If ActiveCell > LargeOrder Then
ActiveCell.Offset(0, 12) = ActiveCell
Else
ActiveCell.Offset(0, 12) = WorksheetFunction.RoundDown(ActiveCell * T9Sell, Rnd - 1) + T9TestDigit
End If
End If
End If
'End If
ActiveCell.Offset(1, 0).Activate
Cnt = 0
Loop
'Easy1 tells how many times the loop has run, needs to check and make sure _
both buys and sells were covered. If AW was true went thru and seperated buys _
and turned into sell then checks to see if there are sells if so then back to _
EasyWay lable now Easy1 = 1 so after checking all sells just steps thru to end sub
If Easy1 = 0 Then
Easy1 = 1
If Range("BA2") <> "" Then Range("BA2").Activate: GoTo EasyWay
End If