Currency Converter

%3CLINGO-SUB%20id%3D%22lingo-sub-2118972%22%20slang%3D%22en-US%22%3ECurrency%20Converter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2118972%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'd%20like%20to%20create%20a%20function%20that%20reads%20the%20currency%20and%20converts%20it%20into%20a%20prefered%20currency%20if%20necessary.%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20have%20a%20table%20that%20includes%20a%20column%20with%20prices%20in%20different%20currencies%20(CHF%20and%20%E2%82%AC).%3C%2FP%3E%3CP%3EIf%20the%20price%20is%20in%20Euro%20I%20want%20it%20to%20be%20converted%20into%20CHF%20according%20to%20the%20defined%20exchange%20rate.%3C%2FP%3E%3CP%3ESo%20far%20I%20got%20the%20following%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20EURO2CHF(Euro%2C%20Kurs)%3CBR%20%2F%3EIf%20Euro.NumberFormat%20%3D%20%22%E2%82%AC%22%20Then%3CBR%20%2F%3EEURO2CHF%20%3D%20Euro%20*%20Kurs%3CBR%20%2F%3EElseIf%20Euro.NumberFormat%20%3D%20%22CHF%22%20Then%3CBR%20%2F%3EEURO2CHF%20%3D%20Euro%20*%201%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20any%20one%20know%20why%20this%20is%20not%20working%20properly%3F%20As%20a%20solution%20I%20always%20get%20CHF%20-%2C%20so%20it%20converts%20the%20currency%20but%20it%20doesn't%20do%20the%20math.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20any%20advices%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2118972%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2119946%22%20slang%3D%22en-US%22%3ERe%3A%20Currency%20Converter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2119946%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F960695%22%20target%3D%22_blank%22%3E%40ExcelDIY%3C%2FA%3E%26nbsp%3BAny%20particular%20reason%20why%20you%20want%20to%20use%20a%20User%20Defined%20Function%20for%20this%20kind%20of%20basic%20operation%3F%20A%20simple%20IF%20statement%20will%20do.%20See%20picture%20below.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202021-02-10%20at%2010.22.22.png%22%20style%3D%22width%3A%20432px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F253812i97939FBF8ED32740%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%202021-02-10%20at%2010.22.22.png%22%20alt%3D%22Screenshot%202021-02-10%20at%2010.22.22.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello

 

I'd like to create a function that reads the currency and converts it into a prefered currency if necessary.

For example, I have a table that includes a column with prices in different currencies (CHF and €).

If the price is in Euro I want it to be converted into CHF according to the defined exchange rate.

So far I got the following code:

 

Function EURO2CHF(Euro, Kurs)
If Euro.NumberFormat = "€" Then
EURO2CHF = Euro * Kurs
ElseIf Euro.NumberFormat = "CHF" Then
EURO2CHF = Euro * 1
End If
End Function

 

Does any one know why this is not working properly? As a solution I always get CHF -, so it converts the currency but it doesn't do the math.

 

Thanks for any advices

1 Reply

@ExcelDIY Any particular reason why you want to use a User Defined Function for this kind of basic operation? A simple IF statement will do. See picture below.

Screenshot 2021-02-10 at 10.22.22.png