+ Reply to Thread
Results 1 to 10 of 10

Problem passing value to function

  1. #1
    Registered User
    Join Date
    05-14-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Problem passing value to function

    Hi.

    I wrote a simple function to calculate the number of weeks a certain stock can last against a production plan.
    The variables I'm using are either integer (4) or double (1). See the arguments definition for your reference:
    Public Function Week_Stock(cini As Integer, cfin As Integer, Stock As Double, row As Integer, prev As Integer)

    All integer variables are passed on perfectly but the Stock variable always passes a zero when indeed it has a much higher number. If I Copy-Paste Values that number, then it works fine.
    I've checked the formatting and it's formatted as number. I tried using the round function to limit the decimals to 3 and it still doesn't work.
    Can anyone help me with this?
    Thanks.
    Pedro

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem passing value to function

    you need to show us the code where you use the function and how you declare the arguments you are passing into the function

    remember to use code tags
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    05-14-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Problem passing value to function

    Hi.
    The code is the following:
    Please Login or Register  to view this content.
    The way to call the function in excel is the following:
    Please Login or Register  to view this content.
    The problem comes from the Stock variable. Cell BU35 has a certain value, e.g. 10000 derived from a formula. If in excel I edit the formula it'll show me the 10000 value. But running the code the value for the Stock variable will be zero. If I copy and paste value the 10000 everything is ok.

    Hope this helps.
    Thanks.
    Pedro
    Last edited by prod75; 05-14-2009 at 09:48 AM. Reason: Added more info

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem passing value to function

    I can not duplicate.

    Can you post workbook example

  5. #5
    Registered User
    Join Date
    05-14-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Problem passing value to function

    Hi.
    I couldn't duplicate the error in a blank workbook. It works perfectly.
    I guess the solution will have to go through copying the entire worksheet to a blank one and see if it solves the issue. I'll try that option and feedback on the outcome.
    Thanks.
    Pedro

  6. #6
    Registered User
    Join Date
    05-14-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Problem passing value to function

    Hi. I decided to start from a blank workbook and build the file again. To my surprise the problem is showing up again.
    Here's the file.
    Problem: Stock although > zero is not being passed onto the function Stock_Range.
    Hope someone can help me.
    Thanks.
    Pedro
    Attached Files Attached Files

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem passing value to function

    For me these are what get passed.

    $G$36 0
    $H$36 0
    $I$36 6599.124
    $J$36 13198.248
    $K$36 19797.372
    $L$36 26243.028
    $M$36 26089.56
    $N$36 25936.092
    $O$36 25782.624
    $P$36 19336.968
    $Q$36 12891.312
    $R$36 6445.656
    $S$36 0

    which matches the cells in the sheet.

  8. #8
    Registered User
    Join Date
    05-14-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Problem passing value to function

    Hi Andy.
    Are you saying that all values are properly passed to the function?
    That would mean the issue is within my excel and not the code or the file?!
    I honestly don't know what else I can do.
    Thanks for the support.
    BR,
    Pedro

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem passing value to function

    I add some more debug code, which produced the following,

    $G$36 0 cini= 7 cfin= 19 stk= 0 rownum= 33 prev= 999
    $H$36 0 cini= 8 cfin= 19 stk= 0 rownum= 33 prev= 999
    $I$36 6599.124 cini= 9 cfin= 19 stk= 6599.124 rownum= 33 prev= 999
    $J$36 13198.248 cini= 10 cfin= 19 stk= 13198.248 rownum= 33 prev= 999
    $K$36 19797.372 cini= 11 cfin= 19 stk= 19797.372 rownum= 33 prev= 999
    $L$36 26243.028 cini= 12 cfin= 19 stk= 26243.028 rownum= 33 prev= 999
    $M$36 26089.56 cini= 13 cfin= 19 stk= 26089.56 rownum= 33 prev= 999
    $N$36 25936.092 cini= 14 cfin= 19 stk= 25936.092 rownum= 33 prev= 999
    $O$36 25782.624 cini= 15 cfin= 19 stk= 25782.624 rownum= 33 prev= 999
    $P$36 19336.968 cini= 16 cfin= 19 stk= 19336.968 rownum= 33 prev= 999
    $Q$36 12891.312 cini= 17 cfin= 19 stk= 12891.312 rownum= 33 prev= 999
    $R$36 6445.656 cini= 18 cfin= 19 stk= 6445.656 rownum= 33 prev= 999
    $S$36 0 cini= 19 cfin= 19 stk= 0 rownum= 33 prev= 999


    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-14-2009
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Problem passing value to function

    Ok, couldn't find out what was causing my macro not to run properly in my pc, so I started to think in a way to still get the end result but without code or with a different code.
    This link shows how to calculate the stock range with a formula avoiding the use of a macro to do it.
    Hope this may help someone with the same need.
    HTML Code: 
    Bye and thanks for the support.
    Pedro

+ 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