+ Reply to Thread
Results 1 to 3 of 3

Compile Error

  1. #1
    Registered User
    Join Date
    01-03-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    2

    Compile Error

    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?
    Attached Files Attached Files
    Last edited by DonkeyOte; 01-03-2011 at 06:07 AM. Reason: modified title

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Compile Error

    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:

    Please Login or Register  to view this content.
    which you could then invoke

    Please 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.
    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)


    Please Login or Register  to view this content.
    so here CubeRoot is now a Function and would be used as such:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-03-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Compile Error

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1