Str to Currency round problem

R

Revenger

Hi,
I have a problem with currency rounding (Excel automatically rounds
currency to 2 decimals).
I have an InputBox in WorkBook_Open event where user enters the currency
....

The procedure goes something like this:

currencystr = InputBox("Please enter currency: ", "Currency ¤")
If currencystr = "" Then
Msgresult = MsgBox("No currency entered ... bla bla, enter ... bla ...",
vbOKOnly,"Error")
Exit sub
Else
currency = currencystr
Sheets(1).Cells(1,1).NumberFormat = "#,##0.0000 $"
Sheets(1).Cells(1,1).Value = Currency
end if

Well, the problem is that the value in the Cells(1,1) is always rounded to
2 decimals and I need 4 !
If I enter 7,4791 Excel rounds it up to 7,5000, and if I enter 7,2319 Excel
shows 7,2300 !

I googled but couldn't find the solution ... can anyone help please ?

Thanks in advance !

--
Pozdrav
Revenger
29.01.2007 09:07:57
Jednom su proizveli Chuck Norris toalet papir, ali papir nije dopustao da
itko sere po njemu.
 
M

Martin Fishlock

Try using double instread of the currency data type.

Also currency = currencystr should produce an error because currency is a
reserved word.

You may also want to check for numerical values on your input.
 
R

Revenger

Try using double instread of the currency data type.

Also currency = currencystr should produce an error because currency is a
reserved word.

You may also want to check for numerical values on your input.

I've resolved the issue ...
I didn't use currency as variable name, my code is not in "english" so I
quickly typed "translated" version of my code ...

The problem was with decimal simbol, since my decimal simbol is "," and
digit grouping symbol is "." but VBA wont work like that.
So i had to replace the "." and "," symbols in currencystr and then write
the value to the cell.

Thanks for the reply !

--
Pozdrav
Revenger
29.01.2007 15:27:43
Jednom su proizveli Chuck Norris toalet papir, ali papir nije dopustao da
itko sere po njemu.
 
D

Dave Peterson

A numberformat of currency can be troublesome.

This worked for me with my USA settings:

Option Explicit
Sub testme()

Dim CurrencyStr As String
Dim myCurrency As Currency

CurrencyStr = InputBox("Please enter currency: ", "Currency ¤")
If CurrencyStr = "" Then
MsgBox "No currency entered ... bla bla, enter ... bla ...", _
vbOKOnly, "Error"
Exit Sub
Else
If IsNumeric(CurrencyStr) Then
myCurrency = CurrencyStr
Sheets(1).Cells(1, 1).NumberFormat = "#,##0.0000 $"
Sheets(1).Cells(1, 1).Value2 = myCurrency
Else
Beep
End If
End If
End Sub

Just in case you find that you still had trouble. (Note the .value2 property.)
 
R

Revenger

Sheets(1).Cells(1, 1).Value2 = myCurrency

Just in case you find that you still had trouble. (Note the .value2 property.)

Thanks for the reply,
I've got it working now,
but this is a good tip (.value2) ...

Thanks for the tip ... didn't know that ...

--
Pozdrav
Revenger
30.01.2007 10:27:25
Jednom su proizveli Chuck Norris toalet papir, ali papir nije dopustao da
itko sere po njemu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top