+ Reply to Thread
Results 1 to 7 of 7

Pass a decimal to a new sub

  1. #1
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Pass a decimal to a new sub

    Hello,

    Can someone please take a quick look at my code and let me know what I'm doing wrong.

    I don't know how to return a decimal, I'm only getting whole numbers. Am I using the wrong data type?

    Also, the IF Else statement is not working. It always returns "You are doing good on gas", regardless of how low the number is.

    As you can tell I'm new writing my own code, but am trying to learn the basics still.

    Thank you,

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Pass a decimal to a new sub

    You defined z (which as I take it should conatin the decimal) as integer which means that z will always be (rounded to) a whole number.
    Define it as single or double and you will get the decimals.

    If necessary you can format z like
    Please Login or Register  to view this content.
    to control the number of decimals to show.
    Last edited by Tsjallie; 10-08-2013 at 02:54 PM. Reason: extra tip
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Pass a decimal to a new sub

    Thank you Tsjallie,

    do you know why my if statement is not working right?

    Please Login or Register  to view this content.
    It always says "You are doing good on gas!!" regardless of the number.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Pass a decimal to a new sub

    That means the value of X always greater than 29?
    How did you calculate z = x/y?

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Pass a decimal to a new sub

    Do you mean X should be Z? Are you evaluating X or Z?

  6. #6
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Pass a decimal to a new sub

    There's nothing wrong with the if-statement, technically spoken.
    I do however think you should evaluate z instead of x, because that represents the consumption ratio.
    I think you also may want to reconsider the ratio of 29. Doesn't seem a very "green" consumption ratio
    And may be you should alter the statement to
    Please Login or Register  to view this content.
    Last edited by Tsjallie; 10-08-2013 at 03:53 PM.

  7. #7
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Pass a decimal to a new sub

    You guys are correct! Sorry it should be "z" not "x". Sorry I had an idiot moment.

+ 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. Use if statement for a range +4 and -4 and write PASS / NOT PASS
    By alexistkd in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-05-2013, 07:11 PM
  2. Replies: 3
    Last Post: 06-07-2012, 07:25 PM
  3. [SOLVED] Analyze Within An Array and Pass Back Once vs. Pass at each applicable Instance
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2012, 05:25 PM
  4. Paste two decimal number in excel without extra decimal places appearing
    By jeffery_frick in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2009, 07:49 PM
  5. Replies: 3
    Last Post: 03-18-2006, 02:25 PM

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