如何在excel中拼写出更少的美元数字时删除“没有美分”?

时间:2014-03-11 14:50:02

标签: excel numbers out spelling

我能够完美地拼出excel中的美元数字。但是我不想要的是什么时候它会说出来#34;没有美分"。所以,如果我想拼出24030,那就说了。它会说二十四万三十美元而不是美分。我希望excel只在它存在时拼出分值。

目前我正在使用微软支持网站上的模块拼出美元价值,这里是链接http://support.microsoft.com/KB/213360

如果有人可以帮助我,我真的很感激。先谢谢了。

如果已经提出这个问题我提前道歉,但在我的辩护中,我无法找到正确的答案。所以希望有人可以在这个问题上帮助我。

2 个答案:

答案 0 :(得分: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

优势在于您可以通过注释掉一行新代码来恢复原始功能。

答案 1 :(得分:0)

您可以从VBA脚本中删除这些行:

Case ""
    Cents = " and No Cents"

或者在你的文字上使用这个公式:

=IF(ISERR(SEARCH(" and no cents",A1)),A1,LEFT(A1,LEN(A1)-13))