【问题标题】:How to remove "no cents" when spelling out cents less dollar figures in excel?在excel中拼出美分减去美元数字时如何删除“无美分”?
【发布时间】:2014-04-15 06:33:59
【问题描述】:
我能够在 Excel 中完美地拼出美元数字。但我不想要的是当它拼出“没有美分”时。所以假设我想拼出 24030。它会说 24030 美元,没有美分。我只希望 excel 仅在存在时才拼出美分值。
目前我正在使用来自微软支持网站的模块拼写美元价值,这里是链接http://support.microsoft.com/KB/213360
如果有人能在这方面帮助我,我将不胜感激。提前致谢。
如果这个问题已经被问过,我提前道歉,但我辩解说我无法找到正确的答案。所以希望有人可以在这个问题上帮助我。
【问题讨论】:
标签:
excel
numbers
out
spelling
【解决方案1】:
我会在 UDF 的末尾添加一行:
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 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
SpellNumber = Dollars & Cents
SpellNumber = Replace(SpellNumber, " and No Cents", "")
End Function
优点是您始终可以通过注释掉一行新代码来返回原始功能。
【解决方案2】:
您可以从 VBA 脚本中删除这些行:
Case ""
Cents = " and No Cents"
或者在你的文字上使用这个公式:
=IF(ISERR(SEARCH(" and no cents",A1)),A1,LEFT(A1,LEN(A1)-13))