Numbers to words (Indian number system) - no Macros

141 views
Skip to first unread message

Karthik Bhat

unread,
May 18, 2008, 1:17:44 AM5/18/08
to ExcelFil...@googlegroups.com
Hi
 
Here is a simple file which converts numbers into words in Indian system.
This file does not use Macros to do the conversion.
 
Thx
KB
 
Numbers to words (Indian number system) - no Macros.xls

Kannan the Great

unread,
Jun 2, 2008, 9:18:12 AM6/2/08
to ExcelFil...@googlegroups.com
Dear Karthik,
 
Great job done.
 
But it doesn''t convert the decimal numbers.
 
This is for your kind ref.
 
Regards,
 
Kannan
 
# / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # / # /

Karthik Bhat

unread,
Jun 3, 2008, 12:54:11 PM6/3/08
to ExcelFiles_India
:) I knew that someone would ask for this sooner or later.

What’s the answer...?? If you have used the above file and tried to
understand how it works you should give a shot at extending the
solution to give up to two decimal places and append the solution to
this post.

Thx
KB

Ritwik...@msn.com

unread,
Jun 4, 2008, 5:25:49 AM6/4/08
to ExcelFiles_India
This might solve!!! ;-)..


Function ConvertCurrencyToINR(ByVal MyNumber)

' This code is based on the orzid article at http://www.ozgrid.com/VBA/CurrencyToWords.htm
' Modifications made by Ritwik Shukla to adjust INR visit
http://ritwik-shukla-vb.blogspot.com for
' more details..

Dim Rupees, Paise, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Lac "
Place(4) = " Crore "
Place(5) = " Arab " '

MyNumber = Trim(Str(MyNumber))
DecimalPlace = InStr(MyNumber, ".")

If DecimalPlace > 0 Then
Paise = ConvertTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
If Count = 1 Then Temp = ConvertHundreds(Right(MyNumber,
3))
If Count > 1 Then Temp = ConvertHundreds(Right(MyNumber,
2))
If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees
If Count = 1 And Len(MyNumber) > 3 Then

MyNumber = Left(MyNumber, Len(MyNumber) - 3)

Else

If Count > 1 And Len(MyNumber) > 2 Then

MyNumber = Left(MyNumber, Len(MyNumber) - 2)

Else

MyNumber = ""

End If

End If

Count = Count + 1

Loop


Select Case Rupees
Case ""
Rupees = "No Rupees"
Case "One"
Rupees = "One Rupee"
Case Else

Rupees = Rupees & " Rupees"

End Select
Select Case Paise
Case ""
Paise = " Only"
Case "One"
Paise = " and One Paisa"
Case Else
Paise = " and " & Paise & " Paise"

End Select
ConvertCurrencyToINR = Rupees & Paise
End Function

Function ConvertHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3) 'Convert the hundreds place
If Mid(MyNumber, 1, 1) <> "0" Then
Result = ConvertMyDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
'Convert the tens and ones place
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & ConvertTens(Mid(MyNumber, 2))
Else
Result = Result & ConvertMyDigit(Mid(MyNumber, 3))
End If
ConvertHundreds = Result
End Function

Function ConvertTens(MyTens)
Dim Result As String
Result = "" 'null out the temporary function value
If Val(Left(MyTens, 1)) = 1 Then ' If value between 10-19
Select Case Val(MyTens)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"

Case Else

End Select

Else ' If value between 20-99

Select Case Val(Left(MyTens, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select

Result = Result & ConvertMyDigit(Right(MyTens, 1))
End If
ConvertTens = Result
End Function

Function ConvertMyDigit(MyDigit)
Select Case Val(MyDigit)
Case 1: ConvertMyDigit = "One"
Case 2: ConvertMyDigit = "Two"
Case 3: ConvertMyDigit = "Three"
Case 4: ConvertMyDigit = "Four"
Case 5: ConvertMyDigit = "Five"
Case 6: ConvertMyDigit = "Six"
Case 7: ConvertMyDigit = "Seven"
Case 8: ConvertMyDigit = "Eight"
Case 9: ConvertMyDigit = "Nine"
Case Else: ConvertMyDigit = ""
End Select
End Function


Ritwik

unread,
Jun 4, 2008, 5:36:42 AM6/4/08
to ExcelFiles_India
Check this UDF...
Psate it in your VBA Excel Module ....

Function ConvertCurrencyToINR(ByVal MyNumber)

' This code is based on the orzid article at http://www.ozgrid.com/VBA/CurrencyToWords.htm
' Modifications made by Ritwik Shukla to adjust INR visit
http://ritwik-shukla-vb.blogspot.com

Reply all
Reply to author
Forward
0 new messages