如何在Excel中快速将数字转换为英文单词?
如果您在工作表中有一列数字值,现在需要将它们设置为等效的英语单词或英语货币单词,如下面的屏幕截图所示。 在这里,我将讨论如何快速,轻松地将数字更改为英语单词。
使用用户定义的功能将数字转换为英文单词
使用用户定义的功能将数字转换为货币词
使用有用的功能将数字转换为货币单词
使用用户定义的功能将数字转换为英文单词
没有任何功能或公式可以帮助您直接在Excel中解决此任务,但是您可以创建一个用户定义函数来完成该任务。 请执行以下步骤:
1. 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序窗口.
2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.
Function NumberstoWords(ByVal MyNumber)
Update by Extendoffice
Dim xStr As String
Dim xFNum As Integer
Dim xStrPoint
Dim xStrNumber
Dim xPoint As String
Dim xNumber As String
Dim xP() As Variant
Dim xDP
Dim xCnt As Integer
Dim xResult, xT As String
Dim xLen As Integer
On Error Resume Next
xP = Array("", "Thousand ", "Million ", "Billion ", "Trillion ", " ", " ", " ", " ")
xNumber = Trim(Str(MyNumber))
xDP = InStr(xNumber, ".")
xPoint = ""
xStrNumber = ""
If xDP > 0 Then
xPoint = " point "
xStr = Mid(xNumber, xDP + 1)
xStrPoint = Left(xStr, Len(xNumber) - xDP)
For xFNum = 1 To Len(xStrPoint)
xStr = Mid(xStrPoint, xFNum, 1)
xPoint = xPoint & GetDigits(xStr) & " "
Next xFNum
xNumber = Trim(Left(xNumber, xDP - 1))
End If
xCnt = 0
xResult = ""
xT = ""
xLen = 0
xLen = Int(Len(Str(xNumber)) / 3)
If (Len(Str(xNumber)) Mod 3) = 0 Then xLen = xLen - 1
Do While xNumber <> ""
If xLen = xCnt Then
xT = GetHundredsDigits(Right(xNumber, 3), False)
Else
If xCnt = 0 Then
xT = GetHundredsDigits(Right(xNumber, 3), True)
Else
xT = GetHundredsDigits(Right(xNumber, 3), False)
End If
End If
If xT <> "" Then
xResult = xT & xP(xCnt) & xResult
End If
If Len(xNumber) > 3 Then
xNumber = Left(xNumber, Len(xNumber) - 3)
Else
xNumber = ""
End If
xCnt = xCnt + 1
Loop
xResult = xResult & xPoint
NumberstoWords = xResult
End Function
Function GetHundredsDigits(xHDgt, xB As Boolean)
Dim xRStr As String
Dim xStrNum As String
Dim xStr As String
Dim xI As Integer
Dim xBB As Boolean
xStrNum = xHDgt
xRStr = ""
On Error Resume Next
xBB = True
If Val(xStrNum) = 0 Then Exit Function
xStrNum = Right("000" & xStrNum, 3)
xStr = Mid(xStrNum, 1, 1)
If xStr <> "0" Then
xRStr = GetDigits(Mid(xStrNum, 1, 1)) & "Hundred "
Else
If xB Then
xRStr = "and "
xBB = False
Else
xRStr = " "
xBB = False
End If
End If
If Mid(xStrNum, 2, 2) <> "00" Then
xRStr = xRStr & GetTenDigits(Mid(xStrNum, 2, 2), xBB)
End If
GetHundredsDigits = xRStr
End Function
Function GetTenDigits(xTDgt, xB As Boolean)
Dim xStr As String
Dim xI As Integer
Dim xArr_1() As Variant
Dim xArr_2() As Variant
Dim xT As Boolean
xArr_1 = Array("Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen ")
xArr_2 = Array("", "", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety ")
xStr = ""
xT = True
On Error Resume Next
If Val(Left(xTDgt, 1)) = 1 Then
xI = Val(Right(xTDgt, 1))
If xB Then xStr = "and "
xStr = xStr & xArr_1(xI)
Else
xI = Val(Left(xTDgt, 1))
If Val(Left(xTDgt, 1)) > 1 Then
If xB Then xStr = "and "
xStr = xStr & xArr_2(Val(Left(xTDgt, 1)))
xT = False
End If
If xStr = "" Then
If xB Then
xStr = "and "
End If
End If
If Right(xTDgt, 1) <> "0" Then
xStr = xStr & GetDigits(Right(xTDgt, 1))
End If
End If
GetTenDigits = xStr
End Function
Function GetDigits(xDgt)
Dim xStr As String
Dim xArr_1() As Variant
xArr_1 = Array("Zero ", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ")
xStr = ""
On Error Resume Next
xStr = xArr_1(Val(xDgt))
GetDigits = xStr
End Function
3。 保存并关闭此代码,然后返回工作表,在空白单元格中输入此公式 = NumberstoWords(A2)( A2 是您要将数字转换为英文单词的单元格),请参见屏幕截图:
4。 然后按 输入 键,然后选择单元格C2,然后将填充手柄拖动到要包含此公式的范围。 所有数字值均已转换为其相应的英语单词。
使用用户定义的功能将数字转换为货币词
如果要将数字转换为英语货币单词,则应应用下面的VBA代码。
1. 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序窗口.
2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.
Function SpellNumberToEnglish(ByVal pNumber)
Update by Extendoffice
Dim Dollars, Cents
arr = Array("", "", " Thousand ", " Million ", " Billion ", " Trillion ")
pNumber = Trim(Str(pNumber))
xDecimal = InStr(pNumber, ".")
If xDecimal > 0 Then
Cents = GetTens(Left(Mid(pNumber, xDecimal + 1) & "00", 2))
pNumber = Trim(Left(pNumber, xDecimal - 1))
End If
xIndex = 1
Do While pNumber <> ""
xHundred = ""
xValue = Right(pNumber, 3)
If Val(xValue) <> 0 Then
xValue = Right("000" & xValue, 3)
If Mid(xValue, 1, 1) <> "0" Then
xHundred = GetDigit(Mid(xValue, 1, 1)) & " Hundred "
End If
If Mid(xValue, 2, 1) <> "0" Then
xHundred = xHundred & GetTens(Mid(xValue, 2))
Else
xHundred = xHundred & GetDigit(Mid(xValue, 3))
End If
End If
If xHundred <> "" Then
Dollars = xHundred & arr(xIndex) & Dollars
End If
If Len(pNumber) > 3 Then
pNumber = Left(pNumber, Len(pNumber) - 3)
Else
pNumber = ""
End If
xIndex = xIndex + 1
Loop
Select Case Dollars
Case ""
Dollars = "No Dollars"
Case "One"
Dollars = "One Dollar"
Case Else
Dollars = Dollars & " Dollars"
End Select
Select Case Cents
Case ""
Cents = " and No Cents"
Case "One"
Cents = " and One Cent"
Case Else
Cents = " and " & Cents & " Cents"
End Select
SpellNumberToEnglish = Dollars & Cents
End Function
Function GetTens(pTens)
Dim Result As String
Result = ""
If Val(Left(pTens, 1)) = 1 Then
Select Case Val(pTens)
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
Select Case Val(Left(pTens, 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(pTens, 1))
End If
GetTens = Result
End Function
Function GetDigit(pDigit)
Select Case Val(pDigit)
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
3。 保存此代码并返回工作表,在空白单元格中输入此公式 = SpellNumberToEnglish(A2)( A2 是您要将数字转换为英语货币单词的单元格),然后将填充手柄向下拖动到要应用此公式的单元格,所有数字均已拼写为英语货币单词,请参见屏幕截图:
使用有用的功能将数字转换为货币单词
上面的代码对于Excel初学者来说有些麻烦,在这里,我将介绍一个有用的功能, Kutools for Excels 数字到单词,使用此实用程序,您可以快速将数字拼写为英文单词或货币单词。
提示:申请这个 数字到单词 功能,首先,您应该下载 Kutools for Excel,然后快速轻松地应用该功能。
安装后 Kutools for Excel,请这样做:
1。 选择要转换的数字列表,然后单击 Kutools > 内容 > 数字到单词,请参见屏幕截图:
2。 在 数字到货币单词 对话框,检查 英语 选项从 语言 列表框,然后单击 Ok 按钮,您将看到所有数字都已拼写成英语货币单词:
Tips:如果要获取英语单词,请检查 不转换为货币 复选框 附加选项 部分,请参见屏幕截图:
点击下载 Kutools for Excel 现在免费试用!
最佳办公生产力工具
将小时转化为分钟 Kutools for Excel!
准备好增强您的 Excel 任务了吗? 利用的力量 Kutools for Excel - 您终极的节省时间的工具。 简化复杂的任务并像专业人士一样浏览数据。 以闪电般的速度体验 Excel!
为什么需要 Kutools for Excel
🛠️ 超过 300 项强大功能: Kutools 包含 300 多项高级功能,可简化您在 1500 多种场景中的工作。
📈 卓越的数据处理能力:合并单元格、删除重复项并执行高级数据转换 - 所有这些都不费吹灰之力!
⏱️ 高效的批量操作:当你可以聪明地工作时,为什么还要付出额外的努力呢? 轻松批量导入、导出、组合和调整数据。
📊 可定制的图表和报告:访问各种附加图表并生成富有洞察力的报告。
🗄️ 强大的导航窗格:通过强大的列管理器、工作表管理器和自定义收藏夹获得优势。
📝 七种类型的下拉列表:通过各种功能和类型的下拉列表使数据输入变得轻而易举。
🎓 用户友好:对于初学者来说轻而易举,对于专家来说是一个强大的工具。
立即下载,与 Excel 一起穿越时空!
阅读更多
免费下载... 采购...
Office Tab 为 Office 带来选项卡式界面,让您的工作更轻松
在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
每天将您的工作效率提高50%,并减少数百次鼠标单击!