Number convert to words
Steps to Add the Macro
- Open Excel and press
ALT + F11
to open the VBA Editor. - Click Insert > Module.
- Copy and paste the code below into the module.
- Close the VBA Editor and return to Excel.
- Use the function in a cell like
=NumberToWords(A1)
.
VBA Code for Digit-by-Digit Conversion
Function NumberToWords(ByVal MyNumber As String) As String
Dim i As Integer
Dim Result As String
Dim Digit As String
' Loop through each digit in the number
For i = 1 To Len(MyNumber)
Digit = Mid(MyNumber, i, 1)
Select Case Digit
Case "0": Result = Result & " Zero"
Case "1": Result = Result & " One"
Case "2": Result = Result & " Two"
Case "3": Result = Result & " Three"
Case "4": Result = Result & " Four"
Case "5": Result = Result & " Five"
Case "6": Result = Result & " Six"
Case "7": Result = Result & " Seven"
Case "8": Result = Result & " Eight"
Case "9": Result = Result & " Nine"
End Select
Next i
' Trim leading space and return the result
NumberToWords = Trim(Result)
End Function
How to Use:
- In Excel, enter a number in a cell (e.g.,
123
in A1). - In another cell, type:
=NumberToWords(A1)
- It will return:
"One Two Three"
Comments
Post a Comment