+ Reply to Thread
Results 1 to 6 of 6

Calling a function

  1. #1
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    Calling a function

    Hi All

    I am trying to write a function at module level. and a macro at sheet level. Basically the operator inputs a value through a input box, It should check in the function and retrieve the value. But it is just diplaying the value that i have input in the inputbox. I am quite naive in writing a function. I am

    Please let me know whats wrong with the below code:

    'At Module Level'

    Please Login or Register  to view this content.
    At the Sheet Level
    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Calling a function

    But it is just diplaying the value that i have input in the inputbox.
    Which is exactly what you have told it to do
    Please Login or Register  to view this content.
    It is not clear to me which of the two values x=200 or y=300 you want returned, but you will a statement assigning x or y to chkfees
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    Re: Calling a function

    Basically at a sheet level when the operator input a value it has to check in the case statment that we have written in the function.

    *For example if a operator inputs a 110000 in the input box (which is there on the sheet level). The fees will be 200
    *For example if a operator inputs a 150000 in the input box (which is there on the sheet level). The fees will be 300

    So the input value should be checked in the case stattment and give the necesscary result.
    Apologies if i was not clear in my first post

    Many Thanx

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Calling a function

    Correct, and I assume the 200 and 300 represent the fees for the two cases. So, you need to assign one of those values (not the original s1_fee that was passed to the function) to the function name. Is there something wrong with the way I assigned x or y to chkfees in the modified code (other than I neglected to comment out the chkfees=s1_fee statement after the select case)?

  5. #5
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    Re: Calling a function

    Do we have to make any changes at sheet level as well. Cos it doesnt return any value. if i am using

    Range("A1").Value = ChkFees(s1_fee)

    However the function just work fine directly in the sheet where i give a value in a cell and use the function in other cell.

    Also just wanted to check my understanding of function little more clearly

    *When we create function it has to return some value , Like ChkFees in my example
    * and the variables declared with in the (...) are the arugments passed to make the function work/create am right ?

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Calling a function

    I would say those are both essentially correct statements about functions.

    As debugging as an important skill, and this one should not be overly difficult to debug, here's a hint/question that I believe will help you see where the problem is: What value are you passing to the function? Or, put another way, what value is in s1_fee when chkfees is called (use the locals window to check variable values while stepping through code http://www.bettersolutions.com/vba/V...D210310551.htm)? Hint: the answer to this question is not related to what you enter in the input box.
    Last edited by MrShorty; 10-04-2013 at 10:58 AM. Reason: fix link

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro exits prematurely from function after calling other function
    By LouisPhilippe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 03:22 AM
  2. [SOLVED] help with calling a function (B) and return control of program flow to the calling functio
    By john/nyc in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-26-2012, 11:06 AM
  3. Function Calling
    By Aphis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-16-2009, 04:27 AM
  4. Calling my function in VBA
    By jasonjenkinson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2006, 10:04 AM
  5. Help with calling a function
    By CR in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-23-2006, 10:40 AM

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