How to Import a Table from a Website to Excel (2 Easy Ways)

We will explore a sample website from which we will fetch a table. In this case, we will visit microsoft.fandom.com. The following website has a table labeled Windows Servers containing two columns: Name and Release date. Using these two approaches, we will import this table from this website to Excel.

import table from website to excel


Method 1 – Utilizing Power Query 

STEPS:

  • In the active sheet, choose cell B4.
  • Go to the Data tab, followed by From Web.

Utilize Power Query to Import Table from Website to Excel

  • The From Web window will pop up.
  • In the URL Box, enter the URL of the Website you want to import tables.
  • Press OK.

  • The Navigator window will open. The left section contains all the tables, while the right section allows us to view each table.
  • Choose Windows Servers. You will see an unnamed column. Import all columns except for this column.
  • To do this, go to Transform Data.

  • The Power Query window will open.
  • Right-click on the top of the column.
  • Select Remove.

Utilize Power Query to Import Table from Website to Excel

  • Go to Close & Load, followed by Close & Load To.

  • The Import Data window opens.
  • Check the Existing worksheet, then press OK.

  • The following result should look like this.

Output of Utilizing Power Query to Import Table from Website to Excel

Read More: How to Scrape Data from a Website into Excel


Method 2 – Using Excel VBA

STEPS:

  • Choose the active sheet of the workbook as Sheet1.
  • Go to Developer.
  • Click Visual Basic.

Import Table from Website Through Excel VBA

  • Select Insert, followed by Module.

  • Enter the following code into the Module Box:
Sub SOFTEKOimporTablefromWeb()
Dim Data As QueryTable
Dim URL As String
URL = "https://microsoft.fandom.com/wiki/List_of_Microsoft_products"
Set Data = Sheet1.QueryTables.Add( _
                Connection:="URL;" & URL, _
                Destination:=Sheet1.Range("B4"))
With Data
.RefreshStyle = xlOverwriteCells
.WebFormatting = xlWebFormattingRTF
.WebSelectionType = xlSpecifiedTables
.WebTables = "2"
.Refresh
End With
End Sub
  • Make sure to change the Range and the URL you want to visit.
  • Press F5 or click the Run button to finish.

  • The result should appear as follows:

Output of Importing Table from Website Through Excel VBA


Download the Practice Workbook

Download the workbook to practice.


Get FREE Advanced Excel Exercises with Solutions!
Lutfor Rahman Shimanto
Lutfor Rahman Shimanto

Lutfor Rahman Shimanto, BSc, Information Technology, Jahangirnagar University, Bangladesh, has worked with the ExcelDemy project for over a year. He has written 50+ articles and provided solutions of 100+ comments for ExcelDemy. Currently, he works as an Excel & VBA Developer and provides support and solutions in the ExcelDemy Forum. He has solved 100+ ExcelDemy Forum problems. His work and learning interests are in developing various Excel & VBA and Desktop applications. Outside of work, he enjoys Chess... Read Full Bio

2 Comments
  1. Thanks for free code and it works for your website.
    However it did not work for Concur Expense;
    Error message as follows:
    “This Web query returned no data. To change the query, click OK, click the arrow on the name box in the
    formula bar, click the name of the eRernaI data range for the Web query, right-click the selection, and then
    click Edit Query. ”

    I suspect User login is a problem.
    Would you help me modify code for above website?
    Thanks and Kind Regards,

    • Reply Lutfor Rahman Shimanto
      Lutfor Rahman Shimanto Nov 30, 2023 at 7:16 PM

      Hello GFIN SUNNY

      Thanks for your nice words. Your appreciation means a lot to us. Thanks once again for sharing your problem.

      Unfortunately, using VBA to automate web interactions with sites that require authentication is not easy when it requires login. You may need a more advanced approach to handle authentication, such as sending HTTP requests with the necessary credentials.

      Regards
      Lutfor Rahman Shimanto

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo