Chrisciuffo
New Member
- Joined
- Jul 21, 2015
- Messages
- 13
-I have 3 columns: todays price, yesterdays price, and the difference
-I need the variation to be between 0 and .20 (in absolute value)
-I'm trying to do multiple iterations on todays price, multiplying it by .999 or 1.001 (depending if its positive or negative), to bring the difference between 0 and .20 in absolute value
-After the value is between 0 and .20, I want to move onto the next cell and do the same alteration to todays price
So far I have used a nested if loop which has worked, but I feel there's a more efficient way of doing it with a do until loop. It would be a great learning experience if someone could help me figure out this code. Below is the code I have now:
For j = 1 To 100 'doing it 100 times to ensure the value is met (between .20 and 0)
For i = 2 To rowcount
If Cells(i, 6) >= 0.19 Then 'And Cells(i, 6) >= 0 Then
Cells(i, 5) = Cells(i, 5) * 0.999 'lower price a little bit
ElseIf Cells(i, 6) <= -0.19 And Cells(i, 6) <= 0 Then
Cells(i, 5) = Cells(i, 5) * 1.001 'raise price a little bit
End If
Next i
Next j
Thanks in advance
-I need the variation to be between 0 and .20 (in absolute value)
-I'm trying to do multiple iterations on todays price, multiplying it by .999 or 1.001 (depending if its positive or negative), to bring the difference between 0 and .20 in absolute value
-After the value is between 0 and .20, I want to move onto the next cell and do the same alteration to todays price
So far I have used a nested if loop which has worked, but I feel there's a more efficient way of doing it with a do until loop. It would be a great learning experience if someone could help me figure out this code. Below is the code I have now:
For j = 1 To 100 'doing it 100 times to ensure the value is met (between .20 and 0)
For i = 2 To rowcount
If Cells(i, 6) >= 0.19 Then 'And Cells(i, 6) >= 0 Then
Cells(i, 5) = Cells(i, 5) * 0.999 'lower price a little bit
ElseIf Cells(i, 6) <= -0.19 And Cells(i, 6) <= 0 Then
Cells(i, 5) = Cells(i, 5) * 1.001 'raise price a little bit
End If
Next i
Next j
Thanks in advance