Excel Numberformat函数不能在给定的数字格式上使用?

时间:2019-07-03 07:24:43

标签: excel vba

我正在用新的数字格式替换现有的数字格式。该代码需要使用计费格式替换。该代码适用于美元,兰特和英镑,但不适用于欧元或AED。我也想基于用户输入创建记帐格式...但是,问题仍然是不能应用数字格式。

我想知道是否有一种方法可以告诉excel根据提供的符号创建自己的会计编号格式。可能是日元,卢比,卢布等

我尝试使用chr代码创建自己的数字格式,但这也不起作用。我尝试用自定义符号替换美元符号,但没有成功。我只想要一种简单的方法即可将工作簿中的所有货币更改为其他用户指定的货币。我想知道为什么程序员没有在vba窗口中包含这样的功能。

Sub curren()
Application.ScreenUpdating = False
    Dim s As Worksheet

Dim initialMode As Long

initialMode = Application.Calculation
Application.Calculation = xlCalculationManual

    Dim strFormat As String
    Dim fin As String

    If Sheets("Summary").Range("e35").NumberFormat = "_-[$$-409]* #,##0.00_ ;_-[$$-409]* -#,##0.00 ;_-[$$-409]* ""-""??_ ;_-@_ " Then
        fin = "_-[$$-409]* #,##0.00_ ;_-[$$-409]* -#,##0.00 ;_-[$$-409]* ""-""??_ ;_-@_ "
        '"_($* #,##0.00_);_($* (#,##0.00);_($* " & Chr(150) & "??_);_(@_)" Then
    ' "_(" & Chr(36) & "* #,##0.00_);_(" & Chr(36) & "* (#,##0.00);_(" & Chr(36) & "* " & Chr(150) & "??_);_(@_)"

    ElseIf Sheets("Summary").Range("e35").NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" Then
        fin = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"

    ElseIf Sheets("Summary").Range("e35").NumberFormat = "_-[$£-452]* #,##0.00_-;-[$£-452]* #,##0.00_-;_-[$£-452]* ""-""??_-;_-@_-" Then
        fin = "_-[$£-452]* #,##0.00_-;-[$£-452]* #,##0.00_-;_-[$£-452]* ""-""??_-;_-@_-"

    ElseIf Sheets("Summary").Range("e35").NumberFormat = "_-[$€-2]* #,##0.00_-;-[$€-2]* #,##0.00_-;_-[$€-2]* ""-""??_-;_-@_-" Then
        fin = "_-[$€-2]* #,##0.00_-;-[$€-2]* #,##0.00_-;_-[$€-2]* ""-""??_-;_-@_-"

    ElseIf Sheets("Summary").Range("e35").NumberFormat = "_-[$AED]* #,##0.00_-;-[$AED]* #,##0.00_-;_-[$AED]* ""-""??_-;_-@_-" Then
        fin = "_-[$AED]* #,##0.00_-;-[$AED]* #,##0.00_-;_-[$AED]* ""-""??_-;_-@_-"

    End If

    Select Case Sheets("Input").Range("e12")
        Case "Dollar"
            strFormat = "_-[$$-409]* #,##0.00_ ;_-[$$-409]* -#,##0.00 ;_-[$$-409]* ""-""??_ ;_-@_ "
        Case "Rand"
            strFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
        Case "Pound"
            strFormat = "_-[$£-452]* #,##0.00_-;-[$£-452]* #,##0.00_-;_-[$£-452]* ""-""??_-;_-@_-"
        Case "Euro"
            strFormat = "_-[$€-2]* #,##0.00_-;-[$€-2]* #,##0.00_-;_-[$€-2]* ""-""??_-;_-@_-"
        Case "Dirham"
            strFormat = "_-[$AED]* #,##0.00_-;-[$AED]* #,##0.00_-;_-[$AED]* ""-""??_-;_-@_-"
    End Select

    Dim x As Boolean

    For Each s In Application.Worksheets
            s.Activate
            x = False
            If s.Visible = xlSheetHidden Then
                s.Visible = xlSheetVisible
                x = True
            End If
Application.FindFormat.NumberFormat = fin
Application.ReplaceFormat.NumberFormat = strFormat

s.Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
    xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
            If x = True Then
                s.Visible = xlSheetHidden
            End If
    Next s
    Application.Calculation = initialMode
Application.ScreenUpdating = True
End Sub

“ Application.ReplaceFormat.NumberFormat = strFormat”

当我选择欧元迪拉姆或我自己指定的会计格式代码时,此代码为我提供了一个错误。

我有一个用户表单,可以获取用户输入,然后必须将该货币与通用记帐格式结合使用,该通用记帐格式将按照代码应用于整个工作簿。

此处未包含其他格式,因为我仍在努力使迪拉姆和欧元每次都能正常工作。

0 个答案:

没有答案
相关问题