Solved

build a currency conversion table in Excel

Posted on 2014-01-18
4
764 Views
Last Modified: 2014-01-30
Hello,

I need to setup a currency conversion table to display something like the following:

1 US      1.64 Pound
2 US       5.66 Franc
1 US      7.76 Hong Kong

If keeping the units is possible, it will be great.

Thanks.
0
Comment
Question by:nav2567
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39791113
Try this sample
Conversion.xlsx
0
 
LVL 81

Expert Comment

by:byundt
ID: 39793258
als315 suggested a VLOOKUP formula for currency conversion. When using formulas like this, it is important to keep track of when you need to multiply by the conversion factor, and when it should be divided by.

For example, for UK Pounds, the conversion factor might be $1.50 US Dollar = 1.0 pound sterling. The formula to convert an amount of US dollars in cell A2 into UK pounds sterling should be:
=A2/VLOOKUP(C2,Sheet2!$A$2:$B$3,2, FALSE)

And the formula to get an amount of US dollars that equal a given amount in UK pounds would be:
=A2*VLOOKUP(C2,Sheet2!$A$2:$B$3,2, FALSE)

I thought it might be nice to get currency exchange rates from a web site using a data query so they can be kept current. I chose www.x-rates.com for this purpose.

I then added some VBA code so you could enter either an amount of US currency or foreign currency and get the corresponding amount in the other currency. This code must be installed in the code pane for the worksheet. As written, the code assumes US Dollars in cell A2, foreign currency in C2 and the name of the foreign currency in D2.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rgUSD As Range, rgCurrency As Range, rgForeign As Range
Set rgUSD = Range("A2")
Set rgForeign = Range("C2")
Set rgCurrency = Range("D2")
If Target.Cells.Count = 1 And Not Intersect(Union(rgUSD, rgForeign), Target) Is Nothing Then
    Application.EnableEvents = False
    If Not Intersect(rgUSD, Target) Is Nothing Then
        If IsNumeric(rgUSD.Value) And rgUSD.Value <> 0 Then
            rgForeign.Formula = _
                "=IF(" & rgCurrency.Address & "="""",""""," & rgUSD.Address & "*VLOOKUP(" & rgCurrency.Address & ",ExchangeRates,2,FALSE))"
        Else
            rgForeign.ClearContents
        End If
    ElseIf Not Intersect(rgForeign, Target) Is Nothing Then
        If rgForeign.HasFormula = False And IsNumeric(rgForeign.Value) And rgForeign.Value <> 0 Then
            rgUSD.Formula = _
                "=IF(" & rgCurrency.Address & "="""",""""," & rgForeign.Address & "/VLOOKUP(" & rgCurrency.Address & ",ExchangeRates,2,FALSE))"
        Else
            rgUSD.ClearContents
        End If
    End If
    Application.EnableEvents = True
End If
End Sub

Open in new window

CurrencyConversionQ28342186.xlsm
0
 
LVL 81

Expert Comment

by:byundt
ID: 39793427
After rereading your question, I see that you have a column of conversions to make. So revised the code so it watches rows 2 through 10 for entry of either US dollars in column A or a foreign currency in column C. The name of the foreign currency is specified in column D. No matter whether you enter an amount in column A or C, the corresponding amount will be calculated in the other column.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rgUSD As Range, rgCurrency As Range, rgForeign As Range
Set rgUSD = Range("A2:A10")         'An amount in US dollars
Set rgForeign = Range("C2:C10")     'An amount in a foreign currency
Set rgCurrency = Range("D2:D10")    'Name of the foreign currency
If Target.Cells.Count = 1 And Not Intersect(Union(rgUSD, rgForeign), Target) Is Nothing Then
    Set rgUSD = Intersect(Target.EntireRow, rgUSD)
    Set rgForeign = Intersect(Target.EntireRow, rgForeign)
    Set rgCurrency = Intersect(Target.EntireRow, rgCurrency)
    Application.EnableEvents = False
    If Not Intersect(rgUSD, Target) Is Nothing Then
        If IsNumeric(rgUSD.Value) And rgUSD.Value <> 0 Then
            rgForeign.Formula = _
                "=IF(" & rgCurrency.Address & "="""",""""," & rgUSD.Address & "*VLOOKUP(" & rgCurrency.Address & ",ExchangeRates,2,FALSE))"
        Else
            rgForeign.ClearContents
        End If
    ElseIf Not Intersect(rgForeign, Target) Is Nothing Then
        If rgForeign.HasFormula = False And IsNumeric(rgForeign.Value) And rgForeign.Value <> 0 Then
            rgUSD.Formula = _
                "=IF(" & rgCurrency.Address & "="""",""""," & rgForeign.Address & "/VLOOKUP(" & rgCurrency.Address & ",ExchangeRates,2,FALSE))"
        Else
            rgUSD.ClearContents
        End If
    End If
    Application.EnableEvents = True
End If
End Sub

Open in new window

CurrencyConversionQ28342186.xlsm
0
 
LVL 23

Accepted Solution

by:
Danny Child earned 500 total points
ID: 39795657
Here's a sheet just doing it with formulae.

Some assumptions - you're always converting another currency to US $
you will always use the standard 3 letter codes to indicate the currency - ie USD, GBP, CAD, etc.  Trying to do it with $ symbols becomes very confusing, when so many countries use the $ symbol, but have different FX rates.  

You could simplify the formulae down to just one calc, but it may be hard to follow, so I left it like this.
ee---FX-rates.xlsx
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel compare strings 6 55
Excel not storing numeric string correctly 5 43
Cell Manipulation 37 54
need a macro to find the 2 letter word in a cell 4 13
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question