Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

[HELP] VBA Currency NumberFormat Error - Excel

$
0
0

[HELP] VBA Currency NumberFormat Error - Excel

Hello,

I've a worksheet with many cells formated as currency and i want modify the currency format through a combobox,

First i use this code to get the inicial currency type/format,

PrivateSub ComboBox1_DropButtonClick()

inicial =Me.ComboBox1.ValueSelectCase inicialCase"EUR"

    oldFormat ="#.##0 €"Case"GBP"

    oldFormat ="[$£-809]#.##0"Case"USD"

    oldFormat ="#.##0 [$USD]"EndSelectEndSub

The oldformat variable is a global variable,

Public oldformat AsString

After that i want to do a find using oldformat variable and a replace using a newformat variable,

PrivateSub ComboBox1_Change()Dim ws As WorksheetDim newFormat AsString'On Error Resume Next
newValue =Me.ComboBox1.ValueSelectCase newValueCase"EUR"

    newFormat ="#.##0 €"Case"GBP"

    newFormat ="[$£-809]#.##0"Case"USD"

    newFormat ="#.##0 [$USD]"EndSelect'Set rNextCell = Application.FindFormatForEach ws In ActiveWorkbook.Worksheets
     Application.FindFormat.Clear
     Application.FindFormat.NumberFormat = oldFormat
     Application.ReplaceFormat.Clear
     Application.ReplaceFormat.NumberFormat = newFormat
     ws.Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder _:=xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=TrueNext wsEndSub

I read the new value through the user choice on the combobox.

But this not work at all, the variables oldformat and newformat receive the correct values but i got a error on,

Run-time error '1004': Application-defined or object-defined error

Application.FindFormat.NumberFormat = oldformat Application.ReplaceFormat.NumberFormat = newFormat

Is there any way to pass the newformat and oldformat value to the Numberformat property?

Or someone have another away to do this?

Link for exemple file,

https://www.dropbox.com/s/sdyfbddxy08pvlc/Change_Currency.xlsm

I apreciate any help, i m a little bit new on .


I apologize if there are any errors in English, is not my natural language.


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>