I'm just starting to learn VBA and am using the "Excel VBA Programming for Dummies" book. I think I've followed the instructions in the example, but I keep getting this error. I'm attaching a print screen of the code and the error. Any suggestions?
I'm just starting to learn VBA and am using the "Excel VBA Programming for Dummies" book. I think I've followed the instructions in the example, but I keep getting this error. I'm attaching a print screen of the code and the error. Any suggestions?
Last edited by DonkeyOte; 01-03-2011 at 06:07 AM. Reason: modified title
In the highlighted routine you are trying to invoke CubeRoot but passing an integer.
Your CubeRoot routine does not have a variable set up (ie can not accept an argument)
To pass the number to CubeRoot you could configure CubeRoot as follows:
which you could then invokePlease Login or Register to view this content.
By defining the variable as Optional in CubeRoot this means you can decide against passing a number if you wish.Please Login or Register to view this content.
Should you do so then when invoked the CubeRoot routine would generate the InputBox
(note I used Application.InputBox so as to be able to specify a valid entry type [number only])
The use of the Do Until Loop is not ideal as you're not offering the end user an Exit Route - they must enter a positive number and complete the routine (ok here but in other scenarios not so good)
If as implied you want CubeRoot to return the resulting value to CallSub then CubeRoot must become a Function (else use appropriate variable scope)
so here CubeRoot is now a Function and would be used as such:Please Login or Register to view this content.
Please Login or Register to view this content.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Wow, thanks for your response. It's still greek to me, but hopefully I'll eventually understand. I'm curious as to why the book would show an example that doesn't work. Hmmmmm?
Thanks again
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks