0% found this document useful (0 votes)
4 views3 pages

SpellNumber Excel VBA

The document contains a VBA function named SpellNumber that converts a numeric value into its corresponding textual representation in Indian currency format, including Rupees and Paise. It utilizes helper functions GetHundreds, GetTens, and GetDigit to break down the number into manageable parts for conversion. The function handles both whole numbers and decimals, formatting the output appropriately.

Uploaded by

decadeafter44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

SpellNumber Excel VBA

The document contains a VBA function named SpellNumber that converts a numeric value into its corresponding textual representation in Indian currency format, including Rupees and Paise. It utilizes helper functions GetHundreds, GetTens, and GetDigit to break down the number into manageable parts for conversion. The function handles both whole numbers and decimals, formatting the output appropriately.

Uploaded by

decadeafter44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Function SpellNumber(ByVal MyNumber)

Dim Units As String


Dim SubUnits As String
Dim TempStr As String
Dim DecimalPlace As Integer
Dim Count As Integer
Dim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Lakh "
Place(4) = " Crore "

Dim Num As String


Dim Rupees As String
Dim Paise As String
Dim DecimalSeparator As String

DecimalSeparator = "."

MyNumber = Trim(Str(MyNumber))
DecimalPlace = InStr(MyNumber, DecimalSeparator)

If DecimalPlace > 0 Then


Units = Left(MyNumber, DecimalPlace - 1)
SubUnits = Mid(MyNumber, DecimalPlace + 1) & "00"
SubUnits = Left(SubUnits, 2)
Else
Units = MyNumber
SubUnits = ""
End If

Count = 1
Do While Units <> ""
Dim Hundreds As String
Hundreds = GetHundreds(Right(Units, 3))
If Hundreds <> "" Then
TempStr = Hundreds & Place(Count) & TempStr
End If
If Len(Units) > 3 Then
Units = Left(Units, Len(Units) - 3)
Else
Units = ""
End If
Count = Count + 1
Loop

Rupees = Application.Trim(TempStr)
If SubUnits <> "" Then
Paise = GetTens(SubUnits)
SpellNumber = Rupees & " Rupees and " & Paise & " Paise"
Else
SpellNumber = Rupees & " Rupees"
End If
End Function
Private Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)

If Mid(MyNumber, 1, 1) <> "0" Then


Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If

If Mid(MyNumber, 2, 1) <> "0" Then


Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If

GetHundreds = Result
End Function

Private Function GetTens(TensText)


Dim Result As String
If Val(Left(TensText, 1)) = 1 Then
Select Case Val(TensText)
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
Select Case Val(Left(TensText, 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 & GetDigit(Right(TensText, 1))
End If
GetTens = Result
End Function

Private Function GetDigit(Digit)


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

You might also like