Convert the Numbers into Words
Public SH As Worksheet
Sub Convert_CellValue_IntoWords()
Set SH = ActiveWorkbook.Sheets("EnterNumber")
SH.Range("F7").Clear
Dim L As Long
L = SH.Range("F3").Value
Dim N As Integer
N = Len(SH.Range("F3").Value)
SH.Range("F7").Activate
If N = 1 Then
BelowTen = SH.Range("F3").Value
LessThanTen (Val(BelowTen))
ElseIf N = 2 Then
FirstNumber = (Mid(L, 1, 1))
BelowNinetyNine = L
LessThanNintyNine (Val(BelowNinetyNine))
ElseIf N = 3 Then
FirstNumber = Val(Mid(L, 1, 1))
BelowNineNinetyNine = L
LessThanNineNintyNine (Val(BelowNineNinetyNine))
ElseIf N = 4 Then
BelowTenThousand = L
LessThanTenThousand (Val(BelowTenThousand))
ElseIf N = 5 Then
BelowOneLakh = L
LessThanOneLakh (Val(BelowOneLakh))
ElseIf N = 6 Then
BelowTenLakhs = L
LessThanTenLakhs (Val(BelowTenLakhs))
ElseIf N = 7 Then
BelowNinetyNineLakhs = L
LessNinetyNineLakhs (BelowNinetyNineLakhs)
ElseIf N >= 8 Then
MsgBox "Length of Number should be less than 8 digits" & vbNewLine & "Exit the Program"
Exit Sub
End If
FormatTheCell
End Sub
Function FormatTheCell()
With ActiveCell
'With SH.Range("F7")
.Font.Size = 22
.Font.Name = "Calibri"
.Font.ColorIndex = 9
.HorizontalAlignment = xlLeft
.Font.Bold = True
End With
End Function
Function LessThanTen(BelowTen)
If BelowTen = 1 Then
LessThanTen = "One"
ElseIf BelowTen = 2 Then
LessThanTen = "Two"
ElseIf BelowTen = 3 Then
LessThanTen = "Three"
ElseIf BelowTen = 4 Then
LessThanTen = "Four"
ElseIf BelowTen = 5 Then
LessThanTen = "Five"
ElseIf BelowTen = 6 Then
LessThanTen = "Six"
ElseIf BelowTen = 7 Then
LessThanTen = "Seven"
ElseIf BelowTen = 8 Then
LessThanTen = "Eight"
ElseIf BelowTen = 9 Then
LessThanTen = "Nine"
End If
ActiveCell.Value = ActiveCell.Value & LessThanTen
End Function
Function LessThanNintyNine(BelowNinetyNine)
FirstNumber = Mid(BelowNinetyNine, 1, 1)
If BelowNinetyNine = 10 Then
LessThanNintyNine = "Ten"
ElseIf BelowNinetyNine = 11 Then
LessThanNintyNine = "Eleven"
ElseIf BelowNinetyNine = 12 Then
LessThanNintyNine = "Twelve"
ElseIf BelowNinetyNine = 13 Then
LessThanNintyNine = "Thirteen"
ElseIf BelowNinetyNine = 14 Then
LessThanNintyNine = "Fourteen"
ElseIf BelowNinetyNine = 15 Then
LessThanNintyNine = "Fifteen"
ElseIf BelowNinetyNine = 16 Then
LessThanNintyNine = "Sixteen"
ElseIf BelowNinetyNine = 17 Then
LessThanNintyNine = "Seventeen"
ElseIf BelowNinetyNine = 18 Then
LessThanNintyNine = "Eighteen"
ElseIf BelowNinetyNine = 19 Then
LessThanNintyNine = "NineTeen"
End If
ActiveCell.Value = ActiveCell.Value & LessThanNintyNine & " "
If LessThanNintyNine = "" Then
If FirstNumber = 2 Then
LessThanNintyNine = "Twenty"
ElseIf FirstNumber = 3 Then
LessThanNintyNine = "Thrity"
ElseIf FirstNumber = 4 Then
LessThanNintyNine = "Fourty"
ElseIf FirstNumber = 5 Then
LessThanNintyNine = "Fifty"
ElseIf FirstNumber = 6 Then
LessThanNintyNine = "Sixty"
ElseIf FirstNumber = 7 Then
LessThanNintyNine = "Seventy"
ElseIf FirstNumber = 8 Then
LessThanNintyNine = "Eighty"
ElseIf FirstNumber = 9 Then
LessThanNintyNine = "Ninety"
End If
ActiveCell.Value = ActiveCell.Value & LessThanNintyNine & " "
'SH.Range("F7").Value = SH.Range("F7").Value & LessThanNintyNine & " "
If FirstNumber = 0 Then
BelowTen = Val(Mid(BelowNinetyNine, 1, 1))
Else: BelowTen = Val(Mid(BelowNinetyNine, 2, 1))
End If
LessThanTen (BelowTen)
End If
End Function
Function LessThanNineNintyNine(BelowNineNinetyNine)
FirstNumber = Val(Mid(BelowNineNinetyNine, 1, 1))
If FirstNumber = 1 Then
LessThanNineNintyNine = "One Hundrend "
ElseIf FirstNumber = 2 Then
LessThanNineNintyNine = "Two Hundrend "
ElseIf FirstNumber = 3 Then
LessThanNineNintyNine = "Three Hundrend "
ElseIf FirstNumber = 4 Then
LessThanNineNintyNine = "Four Hundrend "
ElseIf FirstNumber = 5 Then
LessThanNineNintyNine = "Five Hundrend "
ElseIf FirstNumber = 6 Then
LessThanNineNintyNine = "Six Hundrend "
ElseIf FirstNumber = 7 Then
LessThanNineNintyNine = "Seven Hundrend "
ElseIf FirstNumber = 8 Then
LessThanNineNintyNine = "Eight Hundrend "
ElseIf FirstNumber = 9 Then
LessThanNineNintyNine = "Nine Hundrend "
End If
ActiveCell.Value = ActiveCell.Value & LessThanNineNintyNine
'SH.Range("F7").Value = SH.Range("F7").Value & LessThanNineNintyNine
If Mid(BelowNineNinetyNine, 2, 1) = 0 Then
BelowTen = Val(Mid(BelowNineNinetyNine, 3, 1))
LessThanTen (BelowTen)
Else:
BelowNinetyNine = Val(Mid(BelowNineNinetyNine, 2, 2))
LessThanNintyNine (BelowNinetyNine)
End If
End Function
Function LessThanTenThousand(BelowTenThousand)
FirstNumber = Val(Mid(BelowTenThousand, 1, 1))
If FirstNumber = 1 Then
LessThanTenThousand = "One Thousand "
ElseIf FirstNumber = 2 Then
LessThanTenThousand = "Two Thousand "
ElseIf FirstNumber = 3 Then
LessThanTenThousand = "Three Thousand "
ElseIf FirstNumber = 4 Then
LessThanTenThousand = "Four Thousand "
ElseIf FirstNumber = 5 Then
LessThanTenThousand = "Five Thousand "
ElseIf FirstNumber = 6 Then
LessThanTenThousand = "Six Thousand "
ElseIf FirstNumber = 7 Then
LessThanTenThousand = "Seven Thousand "
ElseIf FirstNumber = 8 Then
LessThanTenThousand = "Eight Thousand "
ElseIf FirstNumber = 9 Then
LessThanTenThousand = "Nine Thousand "
End If
ActiveCell.Value = ActiveCell.Value & LessThanTenThousand
If Mid(BelowTenThousand, 2, 1) = 0 And Mid(BelowTenThousand, 3, 1) = 0 Then
BelowTen = Val(Mid(BelowTenThousand, 4, 1))
LessThanTen (BelowTen)
ElseIf Mid(BelowTenThousand, 2, 1) = 0 Then
BelowNinetyNine = Val(Mid(BelowTenThousand, 3, 2))
LessThanNintyNine (BelowNinetyNine)
Else: BelowNineNinetyNine = Val(Mid(BelowTenThousand, 2, 3))
LessThanNineNintyNine (BelowNineNinetyNine)
End If
End Function
Function LessThanOneLakh(BelowOneLakh)
FirstTwoNumbers = Val(Mid(BelowOneLakh, 1, 2))
If FirstTwoNumbers = 11 Then
LessThanOneLakh = "Eleven "
ElseIf FirstTwoNumbers = 12 Then
LessThanOneLakh = "Twelve "
ElseIf FirstTwoNumbers = 13 Then
LessThanOneLakh = "Thirteen "
ElseIf FirstTwoNumbers = 14 Then
LessThanOneLakh = "Fourteen "
ElseIf FirstTwoNumbers = 15 Then
LessThanOneLakh = "Fifteen "
ElseIf FirstTwoNumbers = 16 Then
LessThanOneLakh = "Sixteen "
ElseIf FirstTwoNumbers = 17 Then
LessThanOneLakh = "Seventeen "
ElseIf FirstTwoNumbers = 18 Then
LessThanOneLakh = "Eighteen "
ElseIf FirstTwoNumbers = 19 Then
LessThanOneLakh = "Nineteen "
End If
If LessThanOneLakh <> "" Then
ActiveCell.Value = ActiveCell.Value & LessThanOneLakh & " Thousand "
If Mid(BelowOneLakh, 3, 1) <> 0 Then
BelowNineNinetyNine = Val(Mid(BelowOneLakh, 3, 3))
LessThanNineNintyNine (BelowNineNinetyNine)
ElseIf Mid(BelowOneLakh, 3, 1) = 0 And Mid(BelowOneLakh, 4, 1) = 0 Then
BelowTen = Val(Mid(BelowOneLakh, 5, 1))
LessThanTen (BelowTen)
ElseIf Mid(BelowOneLakh, 3, 1) = 0 Then
BelowNinetyNine = Val(Mid(BelowOneLakh, 4, 2))
LessThanNintyNine (BelowNinetyNine)
End If
End If
If LessThanOneLakh = "" Then
FirstNumber = Val(Mid(BelowOneLakh, 1, 1))
If FirstNumber = 1 Then
LessThanOneLakh = "Ten "
ElseIf FirstNumber = 2 Then
LessThanOneLakh = "Twenty "
ElseIf FirstNumber = 3 Then
LessThanOneLakh = "Thirty "
ElseIf FirstNumber = 4 Then
LessThanOneLakh = "Fourty "
ElseIf FirstNumber = 5 Then
LessThanOneLakh = "Fifty "
ElseIf FirstNumber = 6 Then
LessThanOneLakh = "Sixty "
ElseIf FirstNumber = 7 Then
LessThanOneLakh = "Seventy "
ElseIf FirstNumber = 8 Then
LessThanOneLakh = "Eighty "
ElseIf FirstNumber = 9 Then
LessThanOneLakh = "Ninety "
End If
ActiveCell.Value = ActiveCell.Value & LessThanOneLakh & ""
'SH.Range("F7").Value = SH.Range("F7").Value & LessThanOneLakh & ""
If Mid(BelowOneLakh, 2, 1) = 0 And Mid(BelowOneLakh, 3, 1) = 0 _
And Mid(BelowOneLakh, 4, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & "Thousand "
'SH.Range("F7").Value = SH.Range("F7").Value & "Thousand "
BelowTen = Val(Mid(BelowOneLakh, 5, 1))
LessThanTen (BelowTen)
ElseIf Mid(BelowOneLakh, 2, 1) = 0 And Mid(BelowOneLakh, 3, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & "Thousand "
'SH.Range("F7").Value = SH.Range("F7").Value & "Thousand "
BelowNinetyNine = Val(Mid(BelowOneLakh, 4, 2))
LessThanNintyNine (BelowNinetyNine)
ElseIf Mid(BelowOneLakh, 2, 1) <> 0 Then
BelowTenThousand = Val(Mid(BelowOneLakh, 2, 4))
LessThanTenThousand (BelowTenThousand)
ElseIf Mid(BelowOneLakh, 2, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & "Thousand "
'SH.Range("F7").Value = SH.Range("F7").Value & "Thousand "
BelowNineNinetyNine = Val(Mid(BelowOneLakh, 3, 3))
LessThanNineNintyNine (BelowNineNinetyNine)
End If
End If
End Function
Function LessThanTenLakhs(BelowTenLakhs)
FirstNumber = Val(Mid(BelowTenLakhs, 1, 1))
If FirstNumber = 1 Then
LessThanTenLakhs = "One Lakh "
ElseIf FirstNumber = 2 Then
LessThanTenLakhs = "Two Lakh "
ElseIf FirstNumber = 3 Then
LessThanTenLakhs = "Three Lakh "
ElseIf FirstNumber = 4 Then
LessThanTenLakhs = "Four Lakh "
ElseIf FirstNumber = 5 Then
LessThanTenLakhs = "Five Lakh "
ElseIf FirstNumber = 6 Then
LessThanTenLakhs = "Six Lakh "
ElseIf FirstNumber = 7 Then
LessThanTenLakhs = "Seven Lakh "
ElseIf FirstNumber = 8 Then
LessThanTenLakhs = "Eight Lakh "
ElseIf FirstNumber = 9 Then
LessThanTenLakhs = "Nine Lakh "
End If
ActiveCell.Value = ActiveCell.Value & LessThanTenLakhs
'SH.Range("F7").Value = SH.Range("F7").Value & LessThanTenLakhs
If Mid(BelowTenLakhs, 2, 1) <> 0 Then
BelowOneLakh = Mid(BelowTenLakhs, 2, 5)
LessThanOneLakh (BelowOneLakh)
ElseIf Mid(BelowTenLakhs, 2, 1) = 0 And Mid(BelowTenLakhs, 3, 1) = 0 And _
Mid(BelowTenLakhs, 4, 1) = 0 And Mid(BelowTenLakhs, 5, 1) = 0 Then
BelowTen = Mid(BelowTenLakhs, 6, 1)
LessThanTen (BelowTen)
ElseIf Mid(BelowTenLakhs, 2, 1) = 0 And Mid(BelowTenLakhs, 3, 1) = 0 And _
Mid(BelowTenLakhs, 4, 1) = 0 Then
BelowNinetyNine = Mid(BelowTenLakhs, 5, 2)
LessThanNintyNine (BelowNinetyNine)
ElseIf Mid(BelowTenLakhs, 2, 1) = 0 And Mid(BelowTenLakhs, 3, 1) = 0 Then
BelowNineNinetyNine = Mid(BelowTenLakhs, 4, 3)
LessThanNineNintyNine (BelowNineNinetyNine)
ElseIf Mid(BelowTenLakhs, 2, 1) = 0 Then
BelowTenThousand = Mid(BelowTenLakhs, 3, 4)
LessThanTenThousand (BelowTenThousand)
End If
End Function
Function LessNinetyNineLakhs(BelowNinetyNineLakhs)
FirstTwoNumbers = Val(Mid(BelowNinetyNineLakhs, 1, 2))
If FirstTwoNumbers = 11 Then
LessNinetyNineLakhs = "Eleven "
ElseIf FirstTwoNumbers = 12 Then
LessNinetyNineLakhs = "Twelve "
ElseIf FirstTwoNumbers = 13 Then
LessNinetyNineLakhs = "Thirteen "
ElseIf FirstTwoNumbers = 14 Then
LessNinetyNineLakhs = "Fourteen "
ElseIf FirstTwoNumbers = 15 Then
LessNinetyNineLakhs = "Fifteen "
ElseIf FirstTwoNumbers = 16 Then
LessNinetyNineLakhs = "Sixteen "
ElseIf FirstTwoNumbers = 17 Then
LessNinetyNineLakhs = "Seventeen "
ElseIf FirstTwoNumbers = 18 Then
LessNinetyNineLakhs = "Eighteen "
ElseIf FirstTwoNumbers = 19 Then
LessNinetyNineLakhs = "Nineteen "
End If
If LessNinetyNineLakhs <> "" Then
ActiveCell.Value = ActiveCell.Value & LessNinetyNineLakhs & "Lakhs "
'SH.Range("F7").Value = SH.Range("F7").Value & LessNinetyNineLakhs & "Lakhs "
If Mid(BelowNinetyNineLakhs, 3, 1) <> 0 Then
BelowOneLakh = Val(Mid(BelowNinetyNineLakhs, 3, 5))
LessThanOneLakh (BelowOneLakh)
ElseIf Mid(BelowNinetyNineLakhs, 3, 1) = 0 _
And Mid(BelowNinetyNineLakhs, 4, 1) = 0 And Mid(BelowNinetyNineLakhs, 5, 1) = 0 _
And Mid(BelowNinetyNineLakhs, 6, 1) = 0 Then
BelowTen = Val(Mid(BelowNinetyNineLakhs, 7, 1))
LessThanTen (BelowTen)
ElseIf Mid(BelowNinetyNineLakhs, 3, 1) = 0 And Mid(BelowNinetyNineLakhs, 4, 1) = 0 And _
Mid(BelowNinetyNineLakhs, 5, 1) = 0 Then
BelowNinetyNine = Val(Mid(BelowNinetyNineLakhs, 6, 2))
LessThanNintyNine (BelowNinetyNine)
ElseIf Mid(BelowNinetyNineLakhs, 3, 1) = 0 And Mid(BelowNinetyNineLakhs, 4, 1) = 0 Then
BelowNineNinetyNine = Val(Mid(BelowNinetyNineLakhs, 5, 3))
LessThanNineNintyNine (BelowNineNinetyNine)
ElseIf Mid(BelowNinetyNineLakhs, 3, 1) = 0 Then
BelowTenThousand = Val(Mid(BelowNinetyNineLakhs, 4, 4))
LessThanTenThousand (BelowTenThousand)
End If
End If
If LessNinetyNineLakhs = "" Then
FirstNumber = Val(Mid(BelowNinetyNineLakhs, 1, 1))
If FirstNumber = 1 Then
LessNinetyNineLakhs = "Ten "
ElseIf FirstNumber = 2 Then
LessNinetyNineLakhs = "Twenty "
ElseIf FirstNumber = 3 Then
LessNinetyNineLakhs = "Thirty "
ElseIf FirstNumber = 4 Then
LessNinetyNineLakhs = "Fourty "
ElseIf FirstNumber = 5 Then
LessNinetyNineLakhs = "Fifty "
ElseIf FirstNumber = 6 Then
LessNinetyNineLakhs = "Sixty "
ElseIf FirstNumber = 7 Then
LessNinetyNineLakhs = "Seventy "
ElseIf FirstNumber = 8 Then
LessNinetyNineLakhs = "Eighty "
ElseIf FirstNumber = 9 Then
LessNinetyNineLakhs = "Ninety "
End If
ActiveCell.Value = ActiveCell.Value & LessNinetyNineLakhs
If Mid(BelowNinetyNineLakhs, 2, 1) <> 0 Then
BelowTenLakhs = Val(Mid(BelowNinetyNineLakhs, 2, 6))
LessThanTenLakhs (BelowTenLakhs)
ElseIf Mid(BelowNinetyNineLakhs, 2, 1) = 0 And Mid(BelowNinetyNineLakhs, 3, 1) = 0 _
And Mid(BelowNinetyNineLakhs, 4, 1) = 0 And Mid(BelowNinetyNineLakhs, 5, 1) = 0 _
And Mid(BelowNinetyNineLakhs, 6, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & " Lakhs "
BelowTen = Val(Mid(BelowNinetyNineLakhs, 7, 1))
LessThanTen (BelowTen)
ElseIf Mid(BelowNinetyNineLakhs, 2, 1) = 0 And Mid(BelowNinetyNineLakhs, 3, 1) = 0 _
And Mid(BelowNinetyNineLakhs, 4, 1) = 0 And Mid(BelowNinetyNineLakhs, 5, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & " Lakhs "
BelowNinetyNine = Val(Mid(BelowNinetyNineLakhs, 6, 2))
LessThanNintyNine (BelowNinetyNine)
ElseIf Mid(BelowNinetyNineLakhs, 2, 1) = 0 And Mid(BelowNinetyNineLakhs, 3, 1) = 0 _
And Mid(BelowNinetyNineLakhs, 4, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & " Lakhs "
BelowNineNinetyNine = Val(Mid(BelowNinetyNineLakhs, 5, 3))
LessThanNineNintyNine (BelowNineNinetyNine)
ElseIf Mid(BelowNinetyNineLakhs, 2, 1) = 0 And Mid(BelowNinetyNineLakhs, 3, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & " Lakhs "
BelowTenThousand = Val(Mid(BelowNinetyNineLakhs, 4, 4))
LessThanTenThousand (BelowTenThousand)
ElseIf Mid(BelowNinetyNineLakhs, 2, 1) = 0 Then
ActiveCell.Value = ActiveCell.Value & " Lakhs "
BelowOneLakh = Val(Mid(BelowNinetyNineLakhs, 3, 5))
LessThanOneLakh (BelowOneLakh)
End If
End If
End Function
Sub Convert_RowNumbers_into_Words_Through_Inputbox()
Set SH = ThisWorkbook.Sheets.Add(after:=Sheets("EnterNumber"))
SH.Activate
ActiveWindow.DisplayGridlines = False
Dim MaxNumber As Long
MaxNumber = Application.InputBox("Enter The Number", "www.Tricks12345.Com")
Dim L As Long
Dim N As Integer
For L = 1 To MaxNumber
Application.StatusBar = L
SH.Cells(L, 1).Activate
rownumber = ActiveCell.Row
If L > ActiveCell.Row Then
MsgBox "Maximum numbers are Printed"
End If
N = Len(rownumber)
If N = 1 Then
BelowTen = rownumber
LessThanTen (Val(BelowTen))
ElseIf N = 2 Then
FirstNumber = (Mid(L, 1, 1))
BelowNinetyNine = L
LessThanNintyNine (Val(BelowNinetyNine))
ElseIf N = 3 Then
FirstNumber = Val(Mid(L, 1, 1))
BelowNineNinetyNine = L
LessThanNineNintyNine (Val(BelowNineNinetyNine))
ElseIf N = 4 Then
BelowTenThousand = L
LessThanTenThousand (Val(BelowTenThousand))
ElseIf N = 5 Then
BelowOneLakh = L
LessThanOneLakh (Val(BelowOneLakh))
ElseIf N = 6 Then
BelowTenLakhs = L
LessThanTenLakhs (Val(BelowTenLakhs))
ElseIf N = 7 Then
BelowNinetyNineLakhs = L
LessNinetyNineLakhs (BelowNinetyNineLakhs)
End If
FormatTheCell
Next
SH.Name = "Numbers Upto " & MaxNumber
Application.StatusBar = ""
End Sub