0

我能够在excel中完美地拼出美元数字。但我不想要的是当它拼出“没有美分”时。所以假设我想拼出 24030。它会说 24030 美元,没有美分。我只希望excel仅在存在时才拼出美分值。

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

如果有人可以帮助我,我将不胜感激。提前感谢一堆。

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

4

2 回答 2

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

优点是您始终可以通过注释掉一行新代码来返回原始功能。

于 2014-03-11T15:11:21.500 回答
0

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

Case ""
    Cents = " and No Cents"

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

=IF(ISERR(SEARCH(" and no cents",A1)),A1,LEFT(A1,LEN(A1)-13))
于 2014-03-11T14:54:03.453 回答