montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
VBA Code:
Sub Pytagoras_two()
Dim j As Integer, k As Integer
For j = 2 To 6
For k = 2 To 10180
Cells(k, j + 9).Formula = "=int(trunc(SQRT(" & Cells(k, j).Address & "^2 + " & Cells(k + 1, j).Address & "^2)))"
If Cells(k, j + 9).Formula > 36 Then
Cells(k, j + 9).Formula = "=abs(int(trunc(SQRT(" & Cells(k, j).Address & "^2 + " & Cells(k + 1, j).Address & "^2)))-36)"
End If
'
Next
Next
End Sub
The purpose of this macro is to perform calculations on a range of cells from sheet 1 (B2:F) and display the results on sheet 7 (B2:F). However, it takes more than a minute to complete.
I'm seeking advice on how to optimize this code to make it run faster. Also, I would like to ensure that it operates on the specified sheets and range (sheet 1 array at B2:F and displays results on sheet 7 B2:F).
Thank you all for taking the time to read this and for any suggestions or guidance you can provide to help me improve the efficiency of this VBA macro.