Sub CurrencyUpdate()
Dim cel As Range, cn As Range
Sheets("Currency").QueryTables(1).Refresh
For Each cel In Sheets("Currency").Range("G4:G10000")
If cel.Value <> "" Then
Sheets(Replace(Split(cel.Value, "!")(0), "'", "")).Range(Split(cel.Value, "!")(1)).Value = cel.Offset(, 2).Value
Sheets(Replace(Split(cel.Value, "!")(0), "'", "")).Range(Split(cel.Value, "!")(1)).NumberFormat = cel.Offset(, 2).NumberFormat
End If
Next cel
End Sub
'ee robberbaron 4.Jan.14
'v 11
Sub DoUpdate()
'1. determine output currency. from Input sheet
Dim currcy_idx As Integer, currcy_name As String, currcy_val As Single
currcy_name = Range("Start_of_CurrencyList").Offset(0, 2).Value 'the cell right of tag
'2. get the exchange rate from MSN Money query
currcy_val = Range("Start_of_CurrencyList").Offset(0, 3).Value 'the cell right of tag
'3. for each of the references on Currency sheet, Do CurrencyUpdate macro
'3.1 convert from Dollars to SelectedCurrency
'3.2 format the new value as text (eg INR xx.yy) [done... sort of]
'3.3 copy formatted text to referenced location. [done]
CopyData currcy_name, currcy_val
End Sub
Function GetFormating(currcy_name As String) As String
Set cWS = Sheets("Currency")
Set rFind = cWS.Range("CurrencyFormats").Find(What:=currcy_name, LookAt:=xlWhole)
If rFind Is Nothing Then
'other
Set rFind = cWS.Range("CurrencyFormats").Find(What:="Other", LookAt:=xlWhole)
End If
GetFormating = rFind.Offset(0, 1).NumberFormat
End Function
Sub CopyData(curc_name As String, curc_rate As Single)
Dim cel As Range, cn As Range, dollarval As Double
Sheets("Currency").QueryTables(1).Refresh
For Each cel In Sheets("Currency").Range("G4:G100")
If cel.Value <> "" Then
shtname = Replace(Split(cel.Value, "!")(0), "'", "")
cellid = Split(cel.Value, "!")(1)
dollarval = cel.Offset(0, 1)
cel.Offset(, 2).Value = dollarval / curc_rate
Sheets(shtname).Range(cellid).Value = cel.Offset(, 2).Value
Sheets(shtname).Range(cellid).NumberFormat = GetFormating(curc_name)
End If
Next cel
End Sub
Sub UpdateCurrencyDropDown()
Sheets("Currency").QueryTables(1).Refresh
Waite 2 'for refresh
Dim rng As Range, currcy As Range
Set rng = Range("Start_of_CurrencyList").Offset(1, 0) 'the row below tag
Set currcy = rng.Offset(0, -9)
Do While Not IsEmpty(currcy)
x = InStr(currcy.Value, " - ")
If x = 0 Then x = Len(currcy.Value)
rng.Value = Left(currcy.Value, x - 1)
rng.Offset(0, 1).Value = currcy.Offset(0, 1).Value
Set rng = rng.Offset(1, 0) 'next row
Set currcy = rng.Offset(0, -9)
Loop
'now reset the range of names
ActiveWorkbook.Names("CurrencyConversions").RefersTo = Range(Range("Start_of_CurrencyList").Offset(1, 0), rng.Offset(-1, 1))
End Sub
Sub Waite(secs As Integer)
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + secs
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
End Sub
Sheets("Currency").QueryTables(1).Refresh
ActiveWorkbook.Names("CurrencyConversions").RefersTo = Range(Range("Start_of_CurrencyList").Offset(1, 0), rng.Offset(-1, 1))
If you do this you'll need to rename that named range the formula I posted earlier.=Currency!$AE$7:INDEX(Currency!$AF:$AF,MATCH(9.99E+307,Currency!$AF:$AF))