Hi,
I have an function that converts foreign currency to US dollars. However, I have to enter the exchange rate data manually into the function. I would like to learn how to populate an array from a worksheet and use that array in my function.
Here is the code I currently have.
The worksheet has two columns: FX symbol and FX rate.
I have an function that converts foreign currency to US dollars. However, I have to enter the exchange rate data manually into the function. I would like to learn how to populate an array from a worksheet and use that array in my function.
Here is the code I currently have.
Rich (BB code):
Function
Rich (BB code):
]ConvertTOUSD(foreignCurrencySymbol As String ,amount As Double ) As Double
Rich (BB code):
Dim ExchangeRates(3, 2) As Variant ,i As Integer
ExchangeRates(0,0) = "Canada"
ExchangeRates(0,1) = "CAD"
ExchangeRates(0,2) = 1.05
ExchangeRates(1,0) = "Euro Zone"
ExchangeRates(1,1) = "EUR"
ExchangeRates(1,2) = 1.2
ExchangeRates(2,0) = "Japan"
ExchangeRates(2,1) = "JPY"
ExchangeRates(2,2) = 0.012
ExchangeRates(3,0) = "Mexico"
ExchangeRates(3,1) = "Mxn"
ExchangeRates(3,2) = 0.07
For i = 0 To UBound(ExchangeRates,1)
If foreignCurrencySymbol= ExchangeRates(i, 1) Then
ConvertTOUSD = amount * ExchangeRates(i, 2)
End If
Next i
End Function
The worksheet has two columns: FX symbol and FX rate.