Range("AQ2").Formula = "=TRUNC(SQRT(Cells(4, 2)^2 + Cells(3, 2)^2))"

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hi.
I think maybe I can get some help here.
so I write this basic formula
VBA Code:
Sub iii()
          Range("AQ2").Formula = "=TRUNC(SQRT(B4^2+B3^2))"
End Sub

and work, but when I tried like


VBA Code:
Sub mrexcel()
          Range("AQ2").Formula = "=TRUNC(SQRT(Cells(4, 2)^2 + Cells(3, 2)^2))"
End Sub

and even worst like

VBA Code:
Sub mx()
      Cells(2, 43).Formula = "=TRUNC(SQRT(Cells(4, 2)^2 + Cells(3, 2)^2))"
End Sub

and according to the theory say that B2 is equal to cells(2,2),so.......
anyone can explain me this.
Please
Thank you for reading
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi.
well working a little bit more I found


VBA Code:
Sub Pal()
            Cells(1, 43) = ((Cells((2), 2) ^ 2) + (Cells((3), 2) ^ 2))
End Sub


here at lease I got the power and add up
so now how to apply the SQRT function, I have testing and still nothing
 
Upvote 0
When you say nothing, do you get an error message?

I've just replicated this.

Your code versions 2 and 3 use Cells to refer to B3 and B4.

Cells is used in VBA and not in a worksheet formula.

If you need to use Cells in VBA, try this idea.

VBA Code:
Cells(6, 4).Formula2 = "=TRUNC(SQRT(" & Cells(4, 2).Address & "^2 + " & Cells(3, 2).Address & "^2))"
 
Upvote 0
Solution
Thank you so much Herakles for your help,
this is what I got when I run this line
1682881596203.png

I am learning so your lesson is really appreciated
 
Upvote 0
VBA Code:
Sub herakles()

    Cells(1, 43).Formula2 = "=TRUNC(SQRT(" & Cells(2, 2).Address & "^2 + " & Cells(3, 2).Address & "^2))"

End Sub
 
Upvote 0
Glad I could help in my very sleepy Sunday evening state. :)

With formulas, I type them into the cell first and if / when they work sometimes use VBA to insert them

I copy and paste the working formula into the VBA editor and then edit it as appropriate.

I don't think that I've ever had a VBA sub named after me. Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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