Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Set references to workbooks and sheets
- Set wbCompany = Workbooks("Company_model_24_draft.xlsx")
- Set wbRates = Workbooks("exchange_rates.xlsx")
- Set wsCompany = wbCompany.Sheets("INDEX1")
- Set wsRates = wbRates.Sheets("monthly_ECB") ' Adjust sheet name as needed
- ' MAKE SURE TO DELETE IRRELEVANT ROWS IN THE EXCHANGE RATES WORKBOOK (e.g. YEARS 2000 - 2022)
- ' Read Reference Currency and Last Fiscal Year Ended
- refCurrency = wsCompany.Range("C5").Value
- lastFiscalYear = wsCompany.Range("C6").Value
- ' Check if D8 or D9 is already 1
- If wsCompany.Range("D8").Value <> 1 Then
- ' Search for the corresponding date range
- For i = 2 To wsRates.Cells(Rows.Count, 2).End(xlUp).Row
- dateRange = wsRates.Cells(i, 2).Value
- If lastFiscalYear >= DateValue(Split(dateRange, " - ")(0)) And lastFiscalYear <= DateValue(Split(dateRange, " - ")(1)) Then
- ' Found the correct date range
- exchangeRateUSD = wsRates.Cells(i, refCurrency & "->USD").Value
- Exit For
- End If
- Next i
- ' Update D8 if not already 1
- wsCompany.Range("D8").Value = exchangeRateUSD
- ElseIf wsCompany.Range("D9").Value <> 1 Then
- ' Search for the corresponding date range (EUR)
- For i = 2 To wsRates.Cells(Rows.Count, 2).End(xlUp).Row
- dateRange = wsRates.Cells(i, 2).Value
- If lastFiscalYear >= DateValue(Split(dateRange, " - ")(0)) And lastFiscalYear <= DateValue(Split(dateRange, " - ")(1)) Then
- ' Found the correct date range
- exchangeRateEUR = wsRates.Cells(i, refCurrency & "->EUR").Value
- Exit For
- End If
- Next i
- ' Update D9 if not already 1
- wsCompany.Range("D9").Value = exchangeRateEUR
- End If
Advertisement
Add Comment
Please, Sign In to add comment