Compile Error: Sub or Function is not defined.

Hailekm

New Member
Joined
Apr 1, 2013
Messages
4
Hi all,
I am beginner in Excel VBA. Before posting this thread I have researched many similar posts but none of the suggestions solved my problem. I am getting compile error. The solver is checked in the reference. The workbook is saved under a new name. Still getting the error for the following piece of code:

Private Sub CommandButton1_Click()
Dim Area As Double, Radius As Double, Perimeter As Double, Diameter As Double
Area = Range("D11").Value
Radius = SQRT(Area / Pi())
Perimeter = 2 * Pi() * Radius
Diameter = 2 * Radius
Range("D13").Value = Perimeter
Range("D15").Value = Diameter
Range("D17").Value = Radius
End Sub


The debugger displays that it does not know (not defined )Pi() and SQRT(). I appreciate your help
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the board

Try

Rich (BB code):
 Radius =   Application.SQRT(Area / Application.Pi())
 Perimeter = 2 * Application.Pi() * Radius
 
Upvote 0
Welcome to the board

Try

Rich (BB code):
 Radius =   Application.SQRT(Area / Application.Pi())
 Perimeter = 2 * Application.Pi() * Radius

Thank you very much really. However, it says
Run Time Error'438':
Object doesn't support this property or method.
 
Upvote 0
In the original code change SQRT to Sqr, which is VBA's equivalent of the Excel worksheet function SQRT.
 
Upvote 0
Once again. Thank you for your help. I modified your suggestion as follows

Radius = Math.Sqr(Area / Application.Pi())
Perimeter = 2 * Application.Pi() * Radius


now it worked for me.
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,338
Members
449,155
Latest member
ravioli44

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