VBA code for SpellNumber like a Cheque Format in Pesos

sheilapretty2

New Member
Joined
Dec 6, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I am new here, i need a vba code like a check format here in the philippines using spellnumber
It will be a great help for me. Thank you.
1701938758078.png
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Directly from Microsoft:
Convert numbers into words - Microsoft Support
If you need something more specific - the code can be altered or you can come up with a more creative formula.

Cheers.
Hi Sir,

I am not an excel pro sir. I'm trying to alter many times but it did not come up
to the result i need. See below a result that i need:
1702345069021.png

I have a VBA code but this code will give me this result:

1702345545031.png


See below VBA CODE I used...

Option Explicit

Function SpellNumber(ByVal Number)

Dim Pesos, Cents, T

Dim Dec, Cnt

ReDim Position(9) As String

Position(2) = " Thousand "

Position(3) = " Million "

Position(4) = " Billion "

Position(5) = " Trillion "

Number = Trim(Str(Number))

Dec = InStr(Number, ".")

If Dec > 0 Then

Cents = GetTens2(Left(Mid(Number, Dec + 1) & _

"00", 2))

Number = Trim(Left(Number, Dec - 1))

End If

Cnt = 1

Do While Number <> ""

T = GetHundreds(Right(Number, 3))

If T <> "" Then Pesos = T & Position(Cnt) & Pesos

If Len(Number) > 3 Then

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

Else

Number = ""

End If

Cnt = Cnt + 1

Loop

Select Case Pesos

Case ""

Pesos = "No Pesos"

Case "One"

Pesos = "One Peso"

Case Else

Pesos = Pesos & ""

End Select

Select Case Cents

Case ""

Cents = ""

Case "One"

Cents = " and One Cent"

Case Else

Cents = " & " & Cents & "/100"

End Select

SpellNumber = "***" & Pesos & Cents & "***"

End Function

Function GetHundreds(ByVal Number)

Dim R As String

If Val(Number) = 0 Then Exit Function

Number = Right("000" & Number, 3)

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

R = GetDigit(Mid(Number, 1, 1)) & " Hundred "

End If

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

R = R & GetTens(Mid(Number, 2))

Else

R = R & GetDigit(Mid(Number, 3))

End If

GetHundreds = R

End Function

Function GetTens(TensText)

Dim R As String

R = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: R = "Ten"

Case 11: R = "Eleven"

Case 12: R = "Twelve"

Case 13: R = "Thirteen"

Case 14: R = "Fourteen"

Case 15: R = "Fifteen"

Case 16: R = "Sixteen"

Case 17: R = "Seventeen"

Case 18: R = "Eighteen"

Case 19: R = "Nineteen"

Case Else

End Select

Else

Select Case Val(Left(TensText, 1))

Case 2: R = "Twenty "

Case 3: R = "Thirty "

Case 4: R = "Forty "

Case 5: R = "Fifty "

Case 6: R = "Sixty "

Case 7: R = "Seventy "

Case 8: R = "Eighty "

Case 9: R = "Ninety "

Case Else

End Select

R = R & GetDigit _

(Right(TensText, 1))

End If

GetTens = R

End Function

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

Function GetTens2(TensText)

Dim R As String

R = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: R = "10"

Case 11: R = "11"

Case 12: R = "12"

Case 13: R = "13"

Case 14: R = "14"

Case 15: R = "15"

Case 16: R = "16"

Case 17: R = "17"

Case 18: R = "18"

Case 19: R = "19"

Case Else

End Select

Else

Select Case Val(Left(TensText, 1))

Case 2: R = "2"

Case 3: R = "3"

Case 4: R = "4"

Case 5: R = "5"

Case 6: R = "6"

Case 7: R = "7"

Case 8: R = "8"

Case 9: R = "9"

Case Else

End Select

R = R & GetDigit2 _

(Right(TensText, 1))

End If

GetTens2 = R

End Function

Function GetDigit2(Digit)

Select Case Val(Digit)

Case 0: GetDigit2 = "0"

Case 1: GetDigit2 = "1"

Case 2: GetDigit2 = "2"

Case 3: GetDigit2 = "3"

Case 4: GetDigit2 = "4"

Case 5: GetDigit2 = "5"

Case 6: GetDigit2 = "6"

Case 7: GetDigit2 = "7"

Case 8: GetDigit2 = "8"

Case 9: GetDigit2 = "9"

Case Else: GetDigit2 = ""

End Select

End Function
 
Upvote 0
VBA Code:
Function SpellNumber(ByVal Number)

Dim Pesos, Cents, T
Dim Dec, Cnt

ReDim Position(9) As String

Position(2) = " Thousand "
Position(3) = " Million "
Position(4) = " Billion "
Position(5) = " Trillion "

Number = Trim(Str(Number))
Dec = InStr(Number, ".")
If Dec > 0 Then
    Cents = GetTens2(Left(Mid(Number, Dec + 1) & "00", 2))
    Number = Trim(Left(Number, Dec - 1))
End If

Cnt = 1

Do While Number <> ""
    T = GetHundreds(Right(Number, 3))
    If T <> "" Then Pesos = T & Position(Cnt) & Pesos
    If Len(Number) > 3 Then
        Number = Left(Number, Len(Number) - 3)
    Else
        Number = ""
    End If
    Cnt = Cnt + 1
Loop

Select Case Pesos
    Case ""
        Pesos = "No Pesos"
    Case "One"
        Pesos = "One Peso"
    Case Else
        Pesos = Pesos & " Pesos"
End Select

Select Case Cents
    Case ""
        Cents = ""
    Case "One"
        Cents = " and One Cent"
    Case Else
        Cents = " & " & Cents & "/100"
End Select

SpellNumber = "***" & Pesos & Cents & "***"
End Function
 
Upvote 0
VBA Code:
Function SpellNumber(ByVal Number)

Dim Pesos, Cents, T
Dim Dec, Cnt

ReDim Position(9) As String

Position(2) = " Thousand "
Position(3) = " Million "
Position(4) = " Billion "
Position(5) = " Trillion "

Number = Trim(Str(Number))
Dec = InStr(Number, ".")
If Dec > 0 Then
    Cents = GetTens2(Left(Mid(Number, Dec + 1) & "00", 2))
    Number = Trim(Left(Number, Dec - 1))
End If

Cnt = 1

Do While Number <> ""
    T = GetHundreds(Right(Number, 3))
    If T <> "" Then Pesos = T & Position(Cnt) & Pesos
    If Len(Number) > 3 Then
        Number = Left(Number, Len(Number) - 3)
    Else
        Number = ""
    End If
    Cnt = Cnt + 1
Loop

Select Case Pesos
    Case ""
        Pesos = "No Pesos"
    Case "One"
        Pesos = "One Peso"
    Case Else
        Pesos = Pesos & " Pesos"
End Select

Select Case Cents
    Case ""
        Cents = ""
    Case "One"
        Cents = " and One Cent"
    Case Else
        Cents = " & " & Cents & "/100"
End Select

SpellNumber = "***" & Pesos & Cents & "***"
End Function
Hi Sir Bobsan42,

Thank you for the code but..........
1702480501399.png


Where can i alter the code.. thank you.
 
Upvote 0
Try the below code :

VBA Code:
Option Explicit

Function SpellNumber(ByVal Number)

Dim Pesos, Cents, T

Dim Dec, Cnt

ReDim Position(9) As String

Position(2) = " Thousand "

Position(3) = " Million "

Position(4) = " Billion "

Position(5) = " Trillion "

Number = Trim(Str(Number))

Dec = InStr(Number, ".")

If Dec > 0 Then

Cents = GetTens2(Left(Mid(Number, Dec + 1) & "00", 2))

Number = Trim(Left(Number, Dec - 1))

End If

Cnt = 1

Do While Number <> ""

T = GetHundreds(Right(Number, 3))

If T <> "" Then Pesos = T & Position(Cnt) & Pesos

If Len(Number) > 3 Then

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

Else

Number = ""

End If

Cnt = Cnt + 1

Loop

Select Case Pesos

Case ""

Pesos = "No Pesos"

Case "One"

Pesos = "One Peso"

Case Else

Pesos = Pesos & ""

End Select

Select Case Cents

Case ""

Cents = " & 00/100"

Case "One"

Cents = " and One Cent"

Case Else

Cents = " & " & Cents & "/100"

End Select

SpellNumber = "***" & Pesos & "Pesos" & Cents & " ***"

End Function

Function GetHundreds(ByVal Number)

Dim R As String

If Val(Number) = 0 Then Exit Function

Number = Right("000" & Number, 3)

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

R = GetDigit(Mid(Number, 1, 1)) & "Hundred "

End If

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

R = R & GetTens(Mid(Number, 2))

Else

R = R & GetDigit(Mid(Number, 3))

End If

GetHundreds = R

End Function

Function GetTens(TensText)

Dim R As String

R = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: R = "Ten "

Case 11: R = "Eleven "

Case 12: R = "Twelve "

Case 13: R = "Thirteen "

Case 14: R = "Fourteen "

Case 15: R = "Fifteen "

Case 16: R = "Sixteen "

Case 17: R = "Seventeen "

Case 18: R = "Eighteen "

Case 19: R = "Nineteen "

Case Else

End Select

Else

Select Case Val(Left(TensText, 1))

Case 2: R = "Twenty "

Case 3: R = "Thirty "

Case 4: R = "Forty "

Case 5: R = "Fifty "

Case 6: R = "Sixty "

Case 7: R = "Seventy "

Case 8: R = "Eighty "

Case 9: R = "Ninety "

Case Else

End Select

R = R & GetDigit(Right(TensText, 1))

End If

GetTens = R

End Function

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

Function GetTens2(TensText)

Dim R As String

R = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: R = "10"

Case 11: R = "11"

Case 12: R = "12"

Case 13: R = "13"

Case 14: R = "14"

Case 15: R = "15"

Case 16: R = "16"

Case 17: R = "17"

Case 18: R = "18"

Case 19: R = "19"

Case Else

End Select

Else

Select Case Val(Left(TensText, 1))

Case 2: R = "2"

Case 3: R = "3"

Case 4: R = "4"

Case 5: R = "5"

Case 6: R = "6"

Case 7: R = "7"

Case 8: R = "8"

Case 9: R = "9"

Case Else

End Select

R = R & GetDigit2(Right(TensText, 1))

End If

GetTens2 = R

End Function

Function GetDigit2(Digit)

Select Case Val(Digit)

Case 0: GetDigit2 = "0"

Case 1: GetDigit2 = "1"

Case 2: GetDigit2 = "2"

Case 3: GetDigit2 = "3"

Case 4: GetDigit2 = "4"

Case 5: GetDigit2 = "5"

Case 6: GetDigit2 = "6"

Case 7: GetDigit2 = "7"

Case 8: GetDigit2 = "8"

Case 9: GetDigit2 = "9"

Case Else: GetDigit2 = ""

End Select

End Function
 
Upvote 0
Try the below code :

VBA Code:
Option Explicit

Function SpellNumber(ByVal Number)

Dim Pesos, Cents, T

Dim Dec, Cnt

ReDim Position(9) As String

Position(2) = " Thousand "

Position(3) = " Million "

Position(4) = " Billion "

Position(5) = " Trillion "

Number = Trim(Str(Number))

Dec = InStr(Number, ".")

If Dec > 0 Then

Cents = GetTens2(Left(Mid(Number, Dec + 1) & "00", 2))

Number = Trim(Left(Number, Dec - 1))

End If

Cnt = 1

Do While Number <> ""

T = GetHundreds(Right(Number, 3))

If T <> "" Then Pesos = T & Position(Cnt) & Pesos

If Len(Number) > 3 Then

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

Else

Number = ""

End If

Cnt = Cnt + 1

Loop

Select Case Pesos

Case ""

Pesos = "No Pesos"

Case "One"

Pesos = "One Peso"

Case Else

Pesos = Pesos & ""

End Select

Select Case Cents

Case ""

Cents = " & 00/100"

Case "One"

Cents = " and One Cent"

Case Else

Cents = " & " & Cents & "/100"

End Select

SpellNumber = "***" & Pesos & "Pesos" & Cents & " ***"

End Function

Function GetHundreds(ByVal Number)

Dim R As String

If Val(Number) = 0 Then Exit Function

Number = Right("000" & Number, 3)

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

R = GetDigit(Mid(Number, 1, 1)) & "Hundred "

End If

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

R = R & GetTens(Mid(Number, 2))

Else

R = R & GetDigit(Mid(Number, 3))

End If

GetHundreds = R

End Function

Function GetTens(TensText)

Dim R As String

R = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: R = "Ten "

Case 11: R = "Eleven "

Case 12: R = "Twelve "

Case 13: R = "Thirteen "

Case 14: R = "Fourteen "

Case 15: R = "Fifteen "

Case 16: R = "Sixteen "

Case 17: R = "Seventeen "

Case 18: R = "Eighteen "

Case 19: R = "Nineteen "

Case Else

End Select

Else

Select Case Val(Left(TensText, 1))

Case 2: R = "Twenty "

Case 3: R = "Thirty "

Case 4: R = "Forty "

Case 5: R = "Fifty "

Case 6: R = "Sixty "

Case 7: R = "Seventy "

Case 8: R = "Eighty "

Case 9: R = "Ninety "

Case Else

End Select

R = R & GetDigit(Right(TensText, 1))

End If

GetTens = R

End Function

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

Function GetTens2(TensText)

Dim R As String

R = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: R = "10"

Case 11: R = "11"

Case 12: R = "12"

Case 13: R = "13"

Case 14: R = "14"

Case 15: R = "15"

Case 16: R = "16"

Case 17: R = "17"

Case 18: R = "18"

Case 19: R = "19"

Case Else

End Select

Else

Select Case Val(Left(TensText, 1))

Case 2: R = "2"

Case 3: R = "3"

Case 4: R = "4"

Case 5: R = "5"

Case 6: R = "6"

Case 7: R = "7"

Case 8: R = "8"

Case 9: R = "9"

Case Else

End Select

R = R & GetDigit2(Right(TensText, 1))

End If

GetTens2 = R

End Function

Function GetDigit2(Digit)

Select Case Val(Digit)

Case 0: GetDigit2 = "0"

Case 1: GetDigit2 = "1"

Case 2: GetDigit2 = "2"

Case 3: GetDigit2 = "3"

Case 4: GetDigit2 = "4"

Case 5: GetDigit2 = "5"

Case 6: GetDigit2 = "6"

Case 7: GetDigit2 = "7"

Case 8: GetDigit2 = "8"

Case 9: GetDigit2 = "9"

Case Else: GetDigit2 = ""

End Select

End Function
Hi Sir Sanjeev1976,

You've got the code..thank you so much on this.

However, can you give me a formula on the below:
1702605047121.png
 
Upvote 0
If your amount is in Cell A1, you can use the below formula

Excel Formula:
="*"&TEXT(A1,"#,###.00")&"*"
 
Upvote 0
Or just custom format the cell as \*#,###.00\* if you are using it just for appearence

1702637493006.png
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top