+ Reply to Thread
Results 1 to 6 of 6

#Name Error in function, cannot run function with green arrow in editor.

  1. #1
    Registered User
    Join Date
    12-12-2011
    Location
    Milwaukee, Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    4

    #Name Error in function, cannot run function with green arrow in editor.

    I am very new to Excel Macros, and have some basic questions.

    I have a excel sheet that has two functions. One calculates the time elapsed, and one is supposed to calculate the number of those hours that fall within a certain time period. However, I keep getting #name error as well as I cannot debut it with the editor after compiling it. I just need help on my major problems, as I am just a N00b teaching himself.

    If you could take a look, that would be swell.
    Peak Hours.xlsm

    Here is just the code that doesn't work
    Please Login or Register  to view this content.


    Thanks a bunch,

    Mike Stanek
    Last edited by staplegunz; 12-29-2011 at 08:03 AM. Reason: Thought I should insert just the code of the function that doesn't work.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: #Name Error in function, cannot run function with green arrow in editor.

    Hi staplegunz,

    VBA is a little different than Excel functions. VBA doesn't know what Time(0,0,0) is.
    Try to Debug.Print your statements in the Immediate window to see if VBA likes them before putting them in the code.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    12-12-2011
    Location
    Milwaukee, Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: #Name Error in function, cannot run function with green arrow in editor.

    Thanks MarvinP,

    I am curious though, I want the time that is output to be in the time format, not a decimal approximation. So if I switch the Time(0,1,0) for the excel decimal equivalent .000694444, wouldn't I have to do some crazy rounding to get it to the right number? Is there any way to use a excel function in VBA?

    Also, I am having trouble using the debug.print, as I cannot run the function. When I press the green button, there are no functions in the pop-up selector box.

    I realize that i have a lot of problems, but thanks again for your help.

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

    Re: #Name Error in function, cannot run function with green arrow in editor.

    A few pointers:

    1 - your Module Name should not conflict with that of a Sub Routine / Function... in this instance your Module and Sub share the same name (change Module name)
    2 - your Sub routine should in fact be a Function (change Sub to Function... at which point the End Sub will auto convert to End Function)
    3 - as MarvinP infers Time should be TimeSerial (change all instances of Time to TimeSerial)
    4 - Time is a Decimal value (Dates being Integers) and so when adding / subtracting etc you should be using standard mathematical operators (change all instances of & to +)

    Once you adjust for the above you should get a value returned within your cell... whether that value is correct or not I've not checked.

    Final pointers...

    a) Debug.Print is used within VBA
    b) Useful also to use Debug -> Compile to validate your code

  5. #5
    Registered User
    Join Date
    12-12-2011
    Location
    Milwaukee, Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: #Name Error in function, cannot run function with green arrow in editor.

    Thanks a bunch. your right, I do get a number now. Ill try playing around with this and see where it takes me.

    Mike

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: #Name Error in function, cannot run function with green arrow in editor.

    A helpful site to understand debugging and the immediate window is at: http://www.cpearson.com/excel/Debug.htm

+ 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