• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

import data from website to excel by changing the dates in web page

Dear Excel experts,

Need your guidance on fetching the data from website to excel. Below are the details I will be required

website: https://www.cbb.gov.bh/facilities-interest-rates/
Import to excel: Exchange Rates - Historical Search (Table)
Date: 1-Jan-2023 to 20-Nov-2023

Require to import the date in below format

can you please help

01-01-2023​
02-01-2023​
03-01-2023​
CurrencyBHD
AED0.102391
ANG0.210101
AUD0.244810
CAD0.274042
CHF0.424591
EUR0.409985
GBP0.468278
HKD0.048235
INR0.004516
JOD0.530439
JPY0.002510
KWD1.219697
LKR0.001148
NOK0.034772
NZD0.225630
OMR0.977494
PKR0.001312
QAR0.103114
USD0.376081
SGD0.279791
SAR0.100275
BDT0.003399
CNY0.052130
EGP0.012171
IDR0.000024
LBP0.000025
MAD0.037095
NPR0.002824
PHP0.006756
THB0.010704
TND0.120608
TRY0.013102
ILS0.101135
 
Hello Chss
You can use VBA to import data from a website to Excel, changing the dates on the web page. Here's a basic example to get you started:


Code:
Sub ImportDataFromWebsite()
    Dim url As String
    Dim startDate As Date
    Dim endDate As Date

    ' Define website URL
    url = "https://www.cbb.gov.bh/facilities-interest-rates/"

    ' Define start and end dates
    startDate = DateValue("01-Jan-2023")
    endDate = DateValue("20-Nov-2023")

    ' Create Internet Explorer object
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")

    ' Navigate to the website
    ie.Navigate url

    ' Wait for the webpage to load
    Do While ie.Busy Or ie.readyState <> 4
        Application.Wait Now + TimeValue("0:00:01")
    Loop

    ' Your code to interact with the webpage and extract data goes here
    ' This may involve finding and clicking elements, filling forms, etc.

    ' Close Internet Explorer
    ie.Quit
    Set ie = Nothing
End Sub


This is a starting point, and you need to adapt the code based on the structure of the website. You may use tools like the Internet Explorer Developer Tools or inspect elements to find the necessary information.

For interacting with the website and extracting data, you might want to explore methods like `getElementById`, `getElementsByClassName`, or `querySelector` in combination with the `innerText` property.

Remember that web scraping may be subject to terms of service of the website, so ensure compliance with the website's policies.
 
Back
Top