Click to See Complete Forum and Search --> : VBA: Roundfunction in Excel 97
Akademos
September 6th, 2001, 06:21 AM
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
Cimperiali
September 6th, 2001, 07:40 AM
'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
Akademos
September 6th, 2001, 07:48 AM
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
Cimperiali
September 6th, 2001, 08:05 AM
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/showpost.pl?Board=vb&Number=57990&Search=true&Forum=vb&Words=scientific&Match=Whole&Topic=&Searchpage=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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.