Code for simple calculation

chadski778

Active Member
Joined
Mar 14, 2010
Messages
297
I'm working my way through VBA for dummies and i'm trying some example code.

Why isn't the following code working?

Sub CubeRoot()
Num = InputBox(“Enter a positive number”)
MsgBox Num ^ (1/3) & “ is the cube root.”
End Sub

This simple procedure asks the user for a number and then displays that​
number’s cube root in a message box. In the VBE the middle two lines turn red when I enter them so there is a compile error
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
It appears to be an issue with the copied text. This works fine:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> CubeRoot()<br>    <SPAN style="color:#00007F">Dim</SPAN> num <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    num = InputBox("Enter a positive number")<br>    <br>    MsgBox num ^ (1 / 3) & " is the Cube Root"<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

HTH,
 
Upvote 0
I'm working my way through VBA for dummies and i'm trying some example code.

Why isn't the following code working?

Sub CubeRoot()
Num = InputBox(Enter a positive number)
MsgBox Num ^ (1/3) & is the cube root.
End Sub

This simple procedure asks the user for a number and then displays that

number’s cube root in a message box. In the VBE the middle two lines turn red when I enter them so there is a compile error
Did you type that code in or copy/paste it from somewhere? The code would work fine if those quote marks were not "stylized" quote marks... VB quote marks are straight up-and-down (like this... ").
 
Upvote 0
Little things like that can make a big difference.

Yes I copied straight from the electronic manual. Marvellous thanks
 
Upvote 0

Forum statistics

Threads
1,226,230
Messages
6,189,768
Members
453,568
Latest member
LaTwiglet85

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