Cells(2, i).Formula = "=trunc(SQRT(" & Cells(2, j).Address & "^2 + " & Cells(3, j).Address & "^2))"

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone.
I have
Book1
BCDEF
1
2811131434
313212527
Sheet1


so the results I expect are

Book1
IJKLM
1
2811242843
Sheet1


and what I have been doing is
VBA Code:
Sub Pytagoras_one()

            Cells(2, 9).Formula = "=trunc(SQRT(" & Cells(2, 2).Address & "^2 + " & Cells(3, 2).Address & "^2))"
            Cells(2, 10).Formula = "=trunc(SQRT(" & Cells(2, 3).Address & "^2 + " & Cells(3, 3).Address & "^2))"
            Cells(2, 11).Formula = "=trunc(SQRT(" & Cells(2, 4).Address & "^2 + " & Cells(3, 4).Address & "^2))"
            Cells(2, 12).Formula = "=trunc(SQRT(" & Cells(2, 5).Address & "^2 + " & Cells(3, 5).Address & "^2))"
            Cells(2, 13).Formula = "=trunc(SQRT(" & Cells(2, 6).Address & "^2 + " & Cells(3, 6).Address & "^2))"


End Sub
so from here I can see a variable 9 to 13 and another 2 to 6 for that then I did
VBA Code:
Sub Pytagoras_two()


For i = 9 To 13
For j = 2 To 6

Cells(2, i).Formula = "=trunc(SQRT(" & Cells(2, j).Address & "^2 + " & Cells(3, j).Address & "^2))"


Next
Next

End Sub
but do not work
so: what I did wrong
thank you for reading this
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
VBA Code:
Sub Pytagoras_two()


For j = 2 To 6

Cells(2, j + 7).Formula = "=trunc(SQRT(" & Cells(2, j).Address & "^2 + " & Cells(3, j).Address & "^2))"


Next

End Sub


This works also. The cell references in the formula will update for each formula.
VBA Code:
Sub Pytagoras_two()

Range("I2:M2").Formula = "=TRUNC(SQRT(B2^2 + B3^2))"

End Sub
 
Last edited:
Upvote 1
Solution

Forum statistics

Threads
1,224,847
Messages
6,181,313
Members
453,031
Latest member
Chris_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top