Converting Digits to Word currency in excell

maxishefy
By maxishefy

Hello
To change Digits to words
Try this
Enter ALT+F11
Open Insert module
Then type the following

Option Explicit
'Main Function
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = "No Qatari Riyals"
Case "One"
Dollars = "One Qatari Riyals"
Case Else
Dollars = Dollars & " Qatari Riyals"
End Select
Select Case Cents
Case ""
Cents = " and No Dirhams"
Case "One"
Cents = " and One Dirhams"
Case Else
Cents = " and " & Cents & " Dirhams"
End Select
SpellNumber = Dollars & Cents
End Function

' Converts a number from 100-999 into text
Function GetHundreds(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 = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
' Convert the tens and ones place.
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

' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
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 ' If value between 20-99...
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)) ' Retrieve ones place.
End If
GetTens = Result
End Function

' Converts a number from 1 to 9 into text.
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

Then go back to your excell file and enter=spellnumber(X)

Regards

By vishnu prathap• 10 Mar 2016 09:38
vishnu prathap

Try this

Option Explicit

'Main Function

Function SpellNumber(ByVal MyNumber)

Dim Riyals, Dirhams, Temp

Dim DecimalPlace, Count

ReDim Place(9) As String

Place(2) = " Thousand "

Place(3) = " Million "

Place(4) = " Billion "

Place(5) = " Trillion "

' String representation of amount.

MyNumber = Trim(Str(MyNumber))

' Position of decimal place 0 if none.

DecimalPlace = InStr(MyNumber, ".")

' Convert Dirhams and set MyNumber to Riyal amount.

If DecimalPlace > 0 Then

Dirhams = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _

"00", 2))

MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

End If

Count = 1

Do While MyNumber ""

Temp = GetHundreds(Right(MyNumber, 3))

If Temp "" Then Riyals = Temp & Place(Count) & Riyals

If Len(MyNumber) > 3 Then

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

Else

MyNumber = ""

End If

Count = Count + 1

Loop

Select Case Riyals

Case ""

Riyals = "No Riyals"

Case "One"

Riyals = "One Riyal"

Case Else

Riyals = Riyals & " Riyals"

End Select

Select Case Dirhams

Case ""

Dirhams = " and No Dirhams"

Case "One"

Dirhams = " and One Dirhams"

Case Else

Dirhams = " and " & Dirhams & " Dirhams"

End Select

SpellNumber = Riyals & Dirhams

End Function

' Converts a number from 100-999 into text

Function GetHundreds(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 = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "

End If

' Convert the tens and ones place.

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

' Converts a number from 10 to 99 into text.

Function GetTens(TensText)

Dim Result As String

Result = "" ' Null out the temporary function value.

If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...

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 ' If value between 20-99...

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)) ' Retrieve ones place.

End If

GetTens = Result

End Function

' Converts a number from 1 to 9 into text.

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

By terry2009• 25 Jan 2016 09:25
terry2009

how I can do without cents, pls post formula removing cents

By vck2498• 12 Apr 2015 14:21
vck2498

Amazing work bro… Thanks…

By anhar4u• 27 Mar 2014 17:45
anhar4u

how to do it for the Qatar Riyal

By Kool Dude• 24 Oct 2010 23:28
Kool Dude

Works perfect,call you tell me how to hide the module and protect it without a password. Obviously, you wouldn'd want any one else to mess it (module)

By maxcaprico• 14 Oct 2010 13:02
maxcaprico

I tried it... can i have the source where i can more of these..

thanks

Log in or register to post comments

More from Qatar Living

Qatar’s top beaches for water sports thrills

Qatar’s top beaches for water sports thrills

Let's dive into the best beaches in Qatar, where you can have a blast with water activities, sports and all around fun times.
Most Useful Apps In Qatar - Part Two

Most Useful Apps In Qatar - Part Two

This guide brings you the top apps that will simplify the use of government services in Qatar.
Most Useful Apps In Qatar - Part One

Most Useful Apps In Qatar - Part One

this guide presents the top must-have Qatar-based apps to help you navigate, dine, explore, access government services, and more in the country.
Winter is coming – Qatar’s seasonal adventures await!

Winter is coming – Qatar’s seasonal adventures await!

Qatar's winter months are brimming with unmissable experiences, from the AFC Asian Cup 2023 to the World Aquatics Championships Doha 2024 and a variety of outdoor adventures and cultural delights.
7 Days of Fun: One-Week Activity Plan for Kids

7 Days of Fun: One-Week Activity Plan for Kids

Stuck with a week-long holiday and bored kids? We've got a one week activity plan for fun, learning, and lasting memories.
Wallet-friendly Mango Sticky Rice restaurants that are delightful on a budget

Wallet-friendly Mango Sticky Rice restaurants that are delightful on a budget

Fasten your seatbelts and get ready for a sweet escape into the world of budget-friendly Mango Sticky Rice that's sure to satisfy both your cravings and your budget!
Places to enjoy Mango Sticky Rice in  high-end elegance

Places to enjoy Mango Sticky Rice in high-end elegance

Delve into a world of culinary luxury as we explore the upmarket hotels and fine dining restaurants serving exquisite Mango Sticky Rice.
Where to celebrate World Vegan Day in Qatar

Where to celebrate World Vegan Day in Qatar

Celebrate World Vegan Day with our list of vegan food outlets offering an array of delectable options, spanning from colorful salads to savory shawarma and indulgent desserts.