TOP

Import of currency rates from the NBU website in Excel

YouLibreCalc for Excel logo

NBU_RATE() Description

A ready-made function for those who often have to use currency rates NBU in Excel .

Helps to automatically obtain the value of the exchange rate from NBU website by its code and date.


VBA code for function NBU_RATE

To add a feature import exchange rates of the NBU , open the menu Service - Macros - Visual Basic Editor , insert the new module (menu Insert - Module ) and copy the text of this function there:

Function NBU_RATE(ByVal pCurrency, ByVal pDate)
  'moonexcel.com.ua 
  If Len(pCurrency) = 0 Or Len(pDate) = 0 Then Exit Function
  
  With WorksheetFunction
    tDate = .Text(pDate, "YYYYMMDD")
    Website = "https://bank.gov.ua/NBU_Exchange/exchange_site"
    RequestString = Website & "?start=" & tDate & "&end=" & tDate & "&valcode=" & pCurrency
    WebServiceResponse = .WebService(RequestString)
    NBU_RATE = .FilterXML(WebServiceResponse, "//rate_per_unit")
  End With
End Function

Close it Visual Basic Editor and return to Excel .

Now you can manually enter our function NBU_RATE() . The syntax of this function is as follows:

=NBU_RATE ( currency code ; date )

We will have the following result:

Using the extension

You can also use the NBUA() function by installing the free extension YouLibreCalc.xlam .

After that, this function will be available in all files that will be opened in Excel.