Monday, April 30, 2012

EXCEL Spell Number Function - AED


Hi,


I have Spell Number Function from MS. Its edited to Dirham format.


Option Explicit
'Main Function
Function SpellNum_Dirham(ByVal MyNumber)
    Dim Dirham, Fils, 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 Fils and set MyNumber to dollar amount.
    If DecimalPlace > 0 Then
        Fils = 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 Dirham = Temp & Place(Count) & Dirham
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Dirham
        Case ""
            Dirham = "No Dirham"
        Case "One"
            Dirham = "One Dollar"
         Case Else
            Dirham = Dirham & " Dirham"
    End Select
    Select Case Fils
        Case ""
            Fils = " and No Fils"
        Case "One"
            Fils = " and One Cent"
              Case Else
            Fils = " and " & Fils & " Fils"
    End Select
    SpellNum_Dirham = Dirham & Fils
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


20 Comments:

Blogger Raza Ali said...

Thank you for dirham formula

November 2, 2013 at 11:21 PM  
Blogger Raza Ali said...

thank you for dirham formula

November 2, 2013 at 11:21 PM  
Blogger kylj said...

thank you.. ^_^

January 5, 2014 at 1:49 PM  
Blogger NITU said...

Try...
Free Excel Add-in Convert Excel cell Numbers to Words with Prefix and Suffix features.
Download Link - http://www.xltool.in

December 2, 2014 at 4:40 PM  
Blogger Unknown said...

Thank you so much...

December 27, 2015 at 10:34 AM  
Blogger Unknown said...

Wonderful!!! Thanks mate. It is helping me a lot. Thanks again. Cheers!!!

February 11, 2016 at 9:52 AM  
Blogger MOHAMMED said...

thank you very much very use full

March 3, 2016 at 12:21 PM  
Blogger Santosh Leo said...

Thanks. Same is there in microsoft site.
But for dollars.
https://support.microsoft.com/en-us/kb/213360

May 9, 2016 at 3:25 PM  
Blogger Unknown said...

DEAR WOULD YOU PLEASE LET ME KNOW HOW CAN I ADD "TOTAL AMOUNT : " IN FRONT OF SPELL ...I.E I WANT TO WRITE "TOTAL AMOUNT : THREE THOUSAND FOUR HUNDRED ONE DIRHAM AND TWENTY FILS"

June 25, 2016 at 2:18 PM  
Blogger Unknown said...

Thank you very much

August 8, 2016 at 11:24 AM  
Blogger JAT said...

Thank you very much

December 2, 2017 at 1:49 PM  
Blogger viji2020 said...

Thank you!

October 31, 2018 at 2:44 PM  
Blogger Varun Ghodela said...

Thank you so Much

July 13, 2019 at 11:19 AM  
Blogger muhammadali said...

Thanks for giving spell number for Dirham ..

every thing is alright except once change

Case "One"
Fils = " and One Cent"

please change it in to fills in order to get 100% Accuracy

thanks


July 31, 2021 at 4:22 PM  
Blogger Unknown said...

Bro have u found any solution for that if yes then plz also tell me

October 18, 2021 at 2:28 PM  
Blogger Unknown said...

TRIED ALL COMMENTS ,THEY ARE NOT WORKING ,....FINALLY THIS WORKING ...

THANK YOU...

January 22, 2022 at 1:39 PM  
Blogger Unknown said...

Thanks for information brother

February 7, 2022 at 7:24 PM  
Blogger Unknown said...

Thanks for sharing the Formula

February 22, 2023 at 12:10 PM  
Blogger Pure Grameen said...

I cant save

May 9, 2024 at 11:36 AM  
Blogger Suvan said...

thanks, works well

June 26, 2024 at 3:57 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home