如何从下拉列表中选择货币,它会快速更改工作簿中的所有货币单元

时间:2019-06-21 13:46:56

标签: excel vba

我正在创建一个私有excel程序,该程序在工作簿中具有多个不同的货币格式单元格。

我想将工作簿中的所有货币单元从一种货币更改为选定的货币。

此过程必须快速有效地进行。

有什么想法吗?

我一直在寻找多个线程,没有运气。我不想找到任何可以快速更改每个货币单元的货币符号的线程。

以下是我尝试过的某些网站的链接: -https://www.pcreview.co.uk/threads/vba-code-to-change-currency-format.3861711/ -https://social.msdn.microsoft.com/Forums/office/en-US/5828423e-96dd-4cae-8404-7d5d8adb328c/finding-all-currency-formatted-cells-and-change-the-currency-symbol?forum=exceldev -https://www.reddit.com/r/excel/comments/4dcha1/i_need_a_way_to_change_all_currency_cells_across/ -https://www.ozgrid.com/forum/forum/help-forums/excel-general/67104-change-currency-symbol-from-list?t=77206 -https://chandoo.org/forum/threads/how-to-change-the-currency-symbol-dynamically-in-excel.7673/ -https://contexturesblog.com/archives/2010/06/23/conditional-formatting-for-currency-symbol/

我没有包括我之前查看过的所有线程。 我只需要快速高效的内容。

代码:

Dim cur As Range
Set cur = Range("e12")


If Not Application.Intersect(cur, Range(Target.Address)) _
       Is Nothing Then
 If cur = "Dollar" Then

    If Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ " Then
    Application.FindFormat.NumberFormat = _
            "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Application.ReplaceFormat.NumberFormat = _
        "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
            "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" Then
    Application.FindFormat.NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    End If



ElseIf cur = "Euro" Then

    If Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ " Then
    Application.FindFormat.NumberFormat = _
            "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
            "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" Then
    Application.FindFormat.NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    End If



ElseIf cur = "Pound" Then
    'dollar to dirham
    If Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ " Then
    Application.FindFormat.NumberFormat = _
            "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Application.ReplaceFormat.NumberFormat = _
        "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
            "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" Then
    Application.FindFormat.NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Application.ReplaceFormat.NumberFormat = _
        "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    End If



ElseIf cur = "Dirham" Then
    'dollar to dirham
    If Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ " Then
    Application.FindFormat.NumberFormat = _
            "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
            "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" Then
    Application.FindFormat.NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Application.ReplaceFormat.NumberFormat = _
        "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    End If




ElseIf cur = "Rand" Then

    If Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ " Then
    Application.FindFormat.NumberFormat = _
            "_-[$$-en-US]* #,##0.00_ ;_-[$$-en-US]* -#,##0.00 ;_-[$$-en-US]* ""-""??_ ;_-@_ "
    Application.ReplaceFormat.NumberFormat = _
        "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
            "_-* #,##0.00 [$€-de-DE]_-;-* #,##0.00 [$€-de-DE]_-;_-* ""-""?? [$€-de-DE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-[$£-en-GB]* #,##0.00_-;-[$£-en-GB]* #,##0.00_-;_-[$£-en-GB]* ""-""??_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-" Then
    Application.FindFormat.NumberFormat = _
    "_-* #,##0.00 [$?.?.?-ar-AE]_-;-* #,##0.00 [$?.?.?-ar-AE]_-;_-* ""-""?? [$?.?.?-ar-AE]_-;_-@_-"
    Application.ReplaceFormat.NumberFormat = _
        "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    ElseIf Sheets("Summary").Range("e15").NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" Then
    Application.FindFormat.NumberFormat = _
    "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Application.ReplaceFormat.NumberFormat = _
        "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    End If
'
'
'
'
End If
End If

1 个答案:

答案 0 :(得分:0)

简单的解决方案:

使if语句成为下拉菜单中的选项。

使此代码在选择新选择时随时运行,并运行所有替换函数,因为没有函数将评估错误。容易绕过,但仍然有效。

代码:

Range(“ o14”)。NumberFormat =“ -[$$-en-US] *#,## 0.00 ; -[$$-en-US] *- #,## 0.00; -[$$-en-US] *“”-“” ?? _; -@ “             Range(“ o18”)。NumberFormat =“ ($ *#,## 0.00 ); ($ *(#,## 0.00); ($ *”“ -“” ???? ); (@ )“                     Range(“ o16”)。NumberFormat =“ -[$$-en-GB] *#,## 0.00 _-;-[$$-en-GB] *#,## 0.00_-; -[[$£-en-GB] *“”-“” ?? -; -@ -“                             Range(“ o15”)。NumberFormat =“ -*#,## 0.00 [$€-de-DE] -;-*#,## 0.00 [$€-de-DE] < em>-; -*“”-“” ?? [$€-de-DE] -; -@ -“                                     Range(“ o17”)。NumberFormat =“ -[$”&“ AED”&“ -en-US] *### 0.00_); [Color46] -([$”&“ AED“&” -en-US] *-### 0.00); -[$“&” AED“&” -en-US] *“”-“” ?? _; ( @ )”