help! with code.

M

manish

hello,
i would like to build a code or module - that would help
me to format the currency on my report in the following
(Indian currency format)

Rs. 5,67,67,89,890.00

ie. first comma after three digits and thereafter after
every two digits.
the problem is i do not know anything about VBA or coding
or how to use a code in the report. so if any helpful
people out there can help me i will be very greatful.

hoping for a solution.
 
D

Dirk Goldgar

manish said:
hello,
i would like to build a code or module - that would help
me to format the currency on my report in the following
(Indian currency format)

Rs. 5,67,67,89,890.00

ie. first comma after three digits and thereafter after
every two digits.
the problem is i do not know anything about VBA or coding
or how to use a code in the report. so if any helpful
people out there can help me i will be very greatful.

hoping for a solution.

You can't achieve this by setting your computer's regional currency
setting appropriately and then using the "currency" format?

If not, I've thrown together the following function. I don't know for
sure that it gives you exactly what you want, and I'm sure it's not the
most efficient implementation, but you could give it a try:

'----- start of code -----
Function fncFormatRupees(pvarAmount As Variant) As String

Dim strFormat1 As String
Dim strSign As String
Dim strFormatted As String
Dim strFirstDigits As String

If Not IsNumeric(pvarAmount) Then
Exit Function
End If

strFormat1 = Format(pvarAmount, "0.00")

strSign = Left$(strFormat1, 1)
If strSign = "-" Then
strFormat1 = Mid$(strFormat1, 2)
Else
strSign = vbNullString
End If

strFormatted = Right$(strFormat1, 6)
strFirstDigits = _
Left(strFormat1, Len(strFormat1) - Len(strFormatted))

While Len(strFirstDigits) > 0
strFormatted = Right$(strFirstDigits, 2) & "," & strFormatted
If Len(strFirstDigits) > 2 Then
strFirstDigits = _
Left$(strFirstDigits, Len(strFirstDigits) - 2)
Else
strFirstDigits = vbNullString
End If
Wend

fncFormatRupees = "Rs. " & strSign & strFormatted

End Function
'----- end of code -----
 

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