My overall goal with the code below is to replace all $ formats in a workbook with £ or € as selected by the user.
However the code seems to get stuck on the line " Application.ReplaceFormat.NumberFormat = ReplaceNew " which returns null.
As far as I can tell, the only reason for this is that the GBP currency/accounting format is not a valid format. It is however, the exact result produced when recording the macro and jives with the format on the cell format (ctrl+1) screen.
Is there some trick to denoting a non-dollar currency in VBA?
Any ideas how to correct the code below?
However the code seems to get stuck on the line " Application.ReplaceFormat.NumberFormat = ReplaceNew " which returns null.
As far as I can tell, the only reason for this is that the GBP currency/accounting format is not a valid format. It is however, the exact result produced when recording the macro and jives with the format on the cell format (ctrl+1) screen.
Is there some trick to denoting a non-dollar currency in VBA?
Any ideas how to correct the code below?
Code:
Sub ChangeCurrency()' ChangeCurrency Macro
' Programmed by Lucas Weiss on 10/31/16
Dim NewCurrency, OldCurrency As String
Dim find1 As String, find2 As String, find3 As String, find4 As String, find5 As String
Dim replace1 As String, replace2 As String, replace3 As String, replace4 As String, replace5 As String
Dim ws As Worksheet
NewCurrency = Range("currency_flag").Value
OldCurrency = "USD"
'Sheets.Select
Select Case OldCurrency
Case "USD"
find1 = "_($* #,##0_);_($* (#,##0);_($* ""-""_);_(@_)" 'accounting w/o decimals
find2 = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)" 'accounting w/ decimals
find3 = "$#,##0.00_);($#,##0.00)" 'currency w decimals
find4 = "$#,##0_);($#,##0)" 'currency w/o decimals
find5 = ",""$" 'in text formulas
Case Else
MsgBox "Existing currency must be changed manually.", 0, "Error: Change Currency Manually"
End Select
Select Case NewCurrency
Case "GBP"
replace1 = "_-[$£-809]* #,##0_-;-[$£-809]* #,##0_-;_-[$£-809]* ""-""_-;_-@_-" 'accounting w/o decimals
replace2 = "_-[$£-809]* #,##0.00_-;-[$£-809]* #,##0.00_-;_-[$£-809]* ""-""??_-;_-@_-" 'accounting w/ decimals
replace3 = "[$£-809]#,##0.00;-[$£-809]#,##0.00" 'currency w decimals
replace4 = "[$£-809]#,##0" 'currency w/o decimals
replace5 = ",""£" 'in text formulas
Case Else
MsgBox "Selected currency must be changed manually.", 0, "Error:Select a Different Currency"
End Select
For Each ws In ActiveWorkbook.Sheets
Call FindReplaceCurrency(find1, replace1)
Call FindReplaceCurrency(find2, replace2)
Call FindReplaceCurrency(find3, replace3)
Call FindReplaceCurrency(find4, replace4)
Cells.Replace What:=find5, Replacement:=replace5, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
Next ws
End Sub
'--------------------------------------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------------------------------------
Sub FindReplaceCurrency(FindOld As String, ReplaceNew As String)
Application.FindFormat.Clear
Application.FindFormat.NumberFormat = FindOld
Application.ReplaceFormat.Clear
[COLOR=#ff0000][B] Application.ReplaceFormat.NumberFormat = ReplaceNew[/B][/COLOR]
Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
End Sub