Results 1 to 14 of 14

Thread: Rounding Up function ??

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Question Rounding Up function ??

    Guys will u please let me know the function (in vba) equivalent to the "roundup" fn available in excell

    i.e i need to round up a value may it be 3.00009 or 3.99999999 the result should be ---> 4

    i can make it up with an if statement but it looks handy with a roundup function



    Secondly I want to create different modules of a program that i have coded into a command button click.
    my purpose is that, the module1 i have created should access the variables declared under the userforum---->cmd_clk
    and also the value i got from the module1 should be accessible to the userforum-->cmd_clk

    Eg.
    under userform---> cmd_clk
    dim a as integer
    dim b as integer
    dim c as integer

    a=a1.text ' a1 is the text box used in userform
    call m1

    c=a+b 'the value of b should be got from module1

    Msgbox(c)

    end sub

    under ---> Module1

    **** m1()

    b=2*a 'b should access the declaration what i made in the cmd_clk
    msgbox(b)

    end sub


    I hope you understand my question.It may be silly for u guys...but i'm new to these coding and stuffs...please just tolerate this..

    waiting for your reply.
    Last edited by dmanojkmr; Nov 21st, 2011 at 12:42 PM.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Rounding Up function ??

    RoundUp
    There is a function which truncate all decimalparts (Int(Yournumber), if you add just 1 to the result you are done.
    Variable-Scope
    Declare all variables in the module and then your done.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Member
    Join Date
    May 2010
    Posts
    60

    Re: Rounding Up function ??

    ceilling?

    I just googled it http://www.tek-tips.com/faqs.cfm?fid=5031
    Last edited by yo mismo; Nov 19th, 2011 at 10:13 PM.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Re: Rounding Up function ??

    @ceiling fn is used in excel not in vba i want something similar to it......int(value)+1 is one way of rounding up a value...but i want to know where there is a direct fn or not.....

    and for my second question

    if i declare the variables in 1 module can other models access these variables and the values in one module are to accessed by other modules and forms.....

    will u please take some more time to correct the above given example of mine to my requirement..
    Last edited by dmanojkmr; Nov 19th, 2011 at 10:40 PM.

  5. #5
    Member
    Join Date
    May 2010
    Posts
    60

    Re: Rounding Up function ??

    No there is not a premade function in vba. Only round and fix function.

    I cannot fix any example because i do not do vba since access 2000 and i have no office at hand.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Re: Rounding Up function ??

    it needn't be a VBA code...try a vb program for it...i'll change it accordingly....

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Rounding Up function ??

    you can use excel ceiling function in excel vba

    vb Code:
    1. rndup = worksheetfunction.ceiling(1.1, 1)

    if i declare the variables in 1 module can other models access these variables
    yes if declared public
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Re: Rounding Up function ??

    @westconn

    did u read my first post ( above)
    can u make a code as per my requirement ????

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Rounding Up function ??

    can u make a code as per my requirement ????
    what is your requirement, that is not covered by suggestions above?
    in excel VBA, you can use either ceiling or roundup worksheetfunctions, or the int function as suggested by opus
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Re: Rounding Up function ??

    Quote Originally Posted by dmanojkmr View Post

    Secondly I want to create different modules of a program that i have coded into a command button click.
    my purpose is that, the module1 i have created should access the variables declared under the userforum---->cmd_clk
    and also the value i got from the module1 should be accessible to the userforum-->cmd_clk

    Eg.
    under userform---> cmd_clk
    dim a as integer
    dim b as integer
    dim c as integer

    a=a1.text ' a1 is the text box used in userform
    call m1

    c=a+b 'the value of b should be got from module1

    Msgbox(c)

    end sub

    under ---> Module1

    **** m1()

    b=2*a 'b should access the declaration what i made in the cmd_clk
    msgbox(b)

    end sub


    I hope you understand my question.It may be silly for u guys...but i'm new to these coding and stuffs...please just tolerate this..

    waiting for your reply.

    I want u to make the above codes as per my requirement....

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Rounding Up function ??

    b=2*a 'b should access the declaration what i made in the cmd_clk
    best way is to pass a to function, rather than using global variables,

    c=a+b 'the value of b should be got from module1
    b should be the return value from a function

    vb Code:
    1. 'under userform---> cmd_clk
    2. dim a as integer
    3. dim b as integer
    4. dim c as integer
    5.  
    6. a=a1.text ' a1 is the text box used in userform
    7. b = m1(a)
    8.  
    9. c=a+b 'the value of b should be got from module1
    10.  
    11. Msgbox(c)
    12.  
    13. end sub
    vb Code:
    1. public funtion m1(a as integer)as integer
    2.  
    3. b=2*a 'b should access the declaration what i made in the cmd_clk
    4. msgbox(b)
    5. m1 = b
    6. end sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Rounding Up function ??

    Can't you just use the built in rounding function and pass it the number to be rounded + .499999999 ?

    Like: MyNumber = Round(TheNumber + 0.4999999)
    Which means if TheNumber is 3.1 or even 3.9 then MyNumber will be 4.0 in either case
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  13. #13

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Resolved Re: Rounding Up function ??

    wow...gr8 thankyou west conn and all other who supported it.....I'l b grateful

    I'll try the above code and reply you...

    thankyou again..

  14. #14

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    39

    Re: Rounding Up function ??

    Hey...guys i got a another problem.....
    actually i thought of using the int()+1 function. but if i want to have the value of 2.1 as 3 but this int+1 fn. makes even 2.0 as 3 which is not desirable .....

    also i can't use the worksheet fn. as i'm in another software called MicroStation a drafting software for mechanical engineers....

    but though i used an if else statement to solve this prob...but it would be nice to have a handy function like Roundup as in excel.

Posting Permissions

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



Click Here to Expand Forum to Full Width