Spell numbers to letters

jackjoush
NewLounger
Posts: 19
Joined: 25 Mar 2021, 21:33

Spell numbers to letters

Post by jackjoush »

Hello everyone
I have the following UDF that spells numbers to words and it is working very well ... but I would like to make one slight change if possible.

Code: Select all

Sub SpellNumbersToLetters()
    Dim Sh As Worksheet, LR As Long, Cel As Range
    Dim Stx1 As String, Stx2 As String, St1 As String, St2 As String, Texte1 As String, Texte2 As String

        For Each Sh In Worksheets(Array("data"))
        LR = Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
        Stx1 = "Dollars ": Stx2 = "Cents ": St1 = "and ": St2 = "No non"

        Texte1 = Ar_WriteDownNumber(Int(Sh.Cells(LR, "T")))
        
        Texte2 = Ar_WriteDownNumber(100 * Sh.Cells(LR, "T") Mod 100)

        With Sh.Cells(LR + 1, "B")
         
         
         If 100 * Sh.Cells(LR, "T") Mod 100 = 0 Then
                
                .Value = "Only " & Texte1 & Stx1 & St2
         Else
               .Value = "Only " & Texte1 & Stx1 & St1 & Texte2 & Stx2 & St2
         End If

        End With
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        Sh.Range(Sh.Cells(LR + 1, "A"), Sh.Cells(LR + 7, "B")).ClearContents
    Next Sh
End Sub
How can spell numbers to words through two cells one for integer and one for decimal As shown in the two cells R & S ?
Please see the attachment file ... Thank you in advance
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78415
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Spell numbers to letters

Post by HansV »

Here is a modified version:

Code: Select all

Sub SpellNumbersToLetters()
    Dim Sh As Worksheet, LR As Long
    Dim Stx1 As String, Stx2 As String, St2 As String, Texte1 As String, Texte2 As String
    Set Sh = Worksheets("data")
    LR = Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
    Stx1 = "Dollars ": Stx2 = "Cents ": St2 = "No non"
    Texte1 = Ar_WriteDownNumber(Sh.Cells(LR, "R"))
    Texte2 = Ar_WriteDownNumber(Sh.Cells(LR, "S"))
    Sh.Cells(LR + 1, "B").Value = "Only " & Texte1 & Stx1 & St2
    Sh.Cells(LR + 1, "M").Value = Texte2 & Stx2 & St2
    Sh.PrintOut Copies:=1
    Sh.Range(Sh.Cells(LR + 1, "A"), Sh.Cells(LR + 7, "M")).ClearContents
End Sub
It writes the Cents value to column M. You can change this to another column if you like.
Best wishes,
Hans

jackjoush
NewLounger
Posts: 19
Joined: 25 Mar 2021, 21:33

Re: Spell numbers to letters

Post by jackjoush »

That's great. Thank you very much for your great help.