montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hi everyone.
This question has to do with programming logic,
Outer loop and inner loop how to decide wich variable will be where and why.
In this presentation I can see clearly what change (variables) and constants.
so how to process this idea, how to pick inner and outer.
so applying the idea mentioned before I come out with
and,,, do not give me the results I was expecting, give me some results but wrong.
This the little example
and this is the right answer
thanks for reading
This question has to do with programming logic,
Outer loop and inner loop how to decide wich variable will be where and why.
In this presentation I can see clearly what change (variables) and constants.
so how to process this idea, how to pick inner and outer.
VBA Code:
Cells(2, 43).Formula = "=trunc(SQRT(" & Cells(2, 2).Address & "^2 + " & Cells(3, 2).Address & "^2))"
Cells(2, 44).Formula = "=trunc(SQRT(" & Cells(2, 3).Address & "^2 + " & Cells(3, 3).Address & "^2))"
Cells(2, 45).Formula = "=trunc(SQRT(" & Cells(2, 4).Address & "^2 + " & Cells(3, 4).Address & "^2))"
Cells(2, 46).Formula = "=trunc(SQRT(" & Cells(2, 5).Address & "^2 + " & Cells(3, 5).Address & "^2))"
Cells(2, 47).Formula = "=trunc(SQRT(" & Cells(2, 6).Address & "^2 + " & Cells(3, 6).Address & "^2))"
VBA Code:
Sub Logic1()
Dim I As Integer
Dim J As Integer
For I = 43 To 47
For J = 2 To 6
Cells(2, I).Formula = "=trunc(SQRT(" & Cells(2, J).Address & "^2 + " & Cells(3, J).Address & "^2))"
Next J
Next I
End Sub
Book1 | ||||||||
---|---|---|---|---|---|---|---|---|
B | C | D | E | F | G | |||
1 | ||||||||
2 | 4 | 5 | 19 | 24 | 36 | |||
3 | 8 | 15 | 18 | 29 | 33 | |||
4 | ||||||||
Sheet1 |
This the little example
and this is the right answer
Book1 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
G | H | I | J | K | L | M | N | |||
1 | ||||||||||
2 | WRONG | 48 | 48 | 48 | 48 | 48 | ||||
3 | ||||||||||
4 | CORRECT | 8 | 15 | 26 | 37 | 48 | ||||
5 | ||||||||||
6 | ||||||||||
Sheet1 |
thanks for reading