Corona Virus Map Graphs – Using Web Query in Excel

.

This post is about how to extract Corona Virus Affected Statistics from
https://www.worldometers.info/coronavirus/ in Excel using WebQuery and create your own Graph, metrics etc. Once you receive the data from Internet through WebQuery it is up to you how you want to do the visualization of that data.

Also this article talks about – How to Refresh any WebQuery using Excel VBA so that you can simply create a Refresh button to load the latest data from the internet.

This article also talks about how to apply data filter on the Extracted data table via WebQuery using Excel VBA.

So let’s begin with !! First and foremost, Don’t panic by seeing the news/ rumors and Myths spreading around. Although you got to be careful with your basic hygiene like washing your hands at least for 20 seconds, using Hand Sanitizers, etc. Try not to travel to those places where more people are affected. You can read more about this Virus and guidelines you can read FAQs about Corona on WHO website and also your local Health Advisory offices and websites. Please take care of you and your loved ones. Stay calm stay safe.

Coming back to the article, this article will cover following topics:

  1. How to Fetch Data from any website in Excel using WebQuery
  2. How to Refresh or Run the WebQeury every time by Clicking on a Button
  3. How to Filter a data Table by a selected value from a ListBox
  4. Download FREE Excel Workbook with Corona Virus Statistics extracted from Web

Let’s start then, to create a Simple WebQuery, in your Excel WorkBook go to Data -> From Web as show in the below picture

From Web - To Fetch Data from Internet

From Web – To Fetch Data from Internet

Click on From Web and provide the Web URL, where you want to fetch the data from as shown in the below Picture

Web URL for Creating WebQuery to Fetch Data from Internet

Once you click on Excel will try to connect to the URL and parse the whole HTML documents available on that URL and categorize it based on simple HTML document, Table etc.

Data Table extracted from the Website URL provided above

Data Table extracted from the Website URL provided above

You can also apply different type of Transformations on the Data you receive from web in a tabular format. As shown in the below picture you will see so many – mostly self explanatory – options available to apply transformation on the data received.

For example, for the Corona Virus Statistics table, I wanted to remove the last row which is a Total Row on the website because I wanted to calculate the default Total from the Excel Table. If I do not remove the last row then the total applied on the table will be doubled.

Extracted Data Table - Transformation Logic

Extracted Data Table – Transformation Logic

Once transformation is done [of course an optional step], table will be extracted in a normal Excel Table like below shown in the picture

Data Table for Graph

Data Table for Graph

Every time you want to refresh this data from the website, you need to click on the refresh button highlighted below on the right hand side

Existing Queries in Excel

Existing Queries in Excel

Excel VBA code to refresh Web data

Basically to refresh the data from a web connection can be done following way

Refreshing a specific Connection by Connection Name

Sub cbRefreshResult()
    Dim wb As Workbook
    Set wb = ThisWorkbook
    wb.Connections("Query - Table 0").Refresh
End Sub

Refreshing all the connections in a Workbook

Sub cbRefreshResults()
    Dim wb As Workbook
    Set wb = ThisWorkbook
    Dim con As WorkbookConnection
    For Each con In wb.Connections
        con.Refresh
    Next con
End Sub

While refreshing you will notice that, your program will end immediately even though the data is still being refreshed. Basically by default Refresh of the data is done in background. In case you want to display a message to the user only when actually refresh is complete, then you need to disable the background processing.

How to disable background Query running

You can disable it simply by executing this statement before executing the refresh method – con.OLEDBConnection.BackgroundQuery = False

Sub cbRefreshResults()
    Dim wb As Workbook
    Set wb = ThisWorkbook
    Dim con As WorkbookConnection

    For Each con In wb.Connections
        ' get the original value
        bBackground = con.OLEDBConnection.BackgroundQuery
        'Temporarily disable background-refresh
        con.OLEDBConnection.BackgroundQuery = False
        'Refresh this connection
        con.Refresh
        'Set background-refresh value back to original value
        con.OLEDBConnection.BackgroundQuery = bBackground
    Next con
    MsgBox "Data Is Refreshed from following site " & vbNewLine & vbNewLine & "https://www.worldometers.info/coronavirus/" & vbNewLine & " Time : " & VBA.Now
End Sub

In the above code, Data Refreshed message will be shown on the screen only when data is loaded completely.

Thank you so much for reading this article. If you like this article, feel free to share it with your friends, colleagues, everyone… Stay Safe and healthy and keep learning

Download Excel Live Graph for Corona Virus Affected Statistics

DOWNLOAD – EXCEL WITH CORONAVIRUS MAP GRAPH AND WEB QUERY. You can refresh the graph with the latest data with one click. Enjoy and stay safe.
Corona Demographics Graph in Excel VBA

Corona Demographics Graph in Excel VBA

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Convert PDF Tables to Excel with VBA | Step-by-Step Guide
Convert PDF Tables to Excel with VBA | Step-by-Step Guide

Convert PDF Tables to Excel with VBA | Step-by-Step Guide How to Convert PDF Tables to Excel Using Excel VBA (Macros) Extracting data from PDF tables into Excel can be tedious, but with Excel VBA (macros), you can automate this process and save time. This guide will...

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

3 Comments

  1. Marcel Eggen

    Great topic to work with in Excel. Is there any way to download your Workbook with Corona Virus Statistics. Can’t see a direct link to it in your article.
    Never actually used web query to get data from the internet. I always use VBA for this.

    Reply
  2. Marco Morotti

    Great job,
    but in my Excel 2016 the math graph doesn’t work: “”This chart isn’t available in your Excekl Version”…

    Best regards. marco

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest