CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    VBA: Roundfunction in Excel 97

    Hi,
    i have made a Excelsheet under Excel 2000. In this Sheet i have VBA-Makros. Some of those Makros are using the VBA-Function Round. Now i have to ship my sheet back to Excel 97. Everything works except the Round Function. Excel 97 tells me that the function doesn't exists.
    Now my question is: Where can i get a VBA-Roundfunction in Excel 97.

    Every hint will help !!

    Thanks

    akademos


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: VBA: Roundfunction in Excel 97


    'Maybe you can write it. The following is an example you can improve
    private Sub CommandButton1_Click()
    MsgBox "15.342 rounded to 2 dec. = " & fnctRound(15.342, 2)
    End Sub
    public Function fnctRound(byval toRoundNumber as Variant, byval number_num as Integer) as Variant
    Dim posPoint as Integer
    Dim tmpNumber as string
    If IsNumeric(toRoundNumber) then
    tmpNumber = CStr(toRoundNumber)
    posPoint = InStr(1, tmpNumber, ".", vbBinaryCompare)
    If posPoint = 0 then
    fnctRound = toRoundNumber
    else
    Dim decNumber as string, i as Integer
    If number_num > 0 then
    decNumber = "0."
    for i = 1 to number_num
    decNumber = decNumber & "0"
    next i
    decNumber = decNumber & "5"
    else
    decNumber = 0
    End If
    toRoundNumber = toRoundNumber + CDbl(decNumber)
    tmpNumber = CStr(toRoundNumber)
    If posPoint = 1 then
    tmpNumber = "0" & tmpNumber
    posPoint = 2
    End If

    'save int part of number
    fnctRound = Left(tmpNumber, posPoint - 1)
    'choose dec part
    If number_num > 0 then
    fnctRound = fnctRound & mid$(tmpNumber, posPoint, number_num + 1)
    End If
    End If
    else
    MsgBox "Not a number " & toRoundNumber
    End If
    End Function






    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    Re: VBA: Roundfunction in Excel 97

    I already wrote something similar. It worked fine until the first entry in scientific notation (9.33222E-09) was made. No i'm looking for a 'real' welltested function to replace my patchwork function



  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: VBA: Roundfunction in Excel 97

    In my environment, a round function for access 97 is described, but even using the "insert function" of the menu, it does not work correctly. You may improve your function using:
    Format(dbl, "#")
    (Kdev suggestment: http://codeguru.com/cgi-bin/bbs/wt/s...age=0&Limit=25)
    to pass from scientific notation to non-scientific one...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured