Downloading a data from a web page and pasting it on an excel Sheet

Mayur Gwalani

New Member
Joined
Jul 13, 2017
Messages
1
[TABLE="width: 1790"]
<colgroup><col></colgroup><tbody>[TR]
[TD="align: left"]
C:\Users\MAYUR~1.GWA\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png
[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Is something like this even possible?[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Thanks in advance for your help![/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this;

Code:
Sub Test()
    Dim URL As String
    Dim IE As Object
    Dim HTML_Body As Object, HTML_Tables As Object, MyTable As Object
    URL = "http://web1.ncaa.org/d1mfb/Internet/national rankings/IA_teamrush.html"

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate URL
    Do Until IE.ReadyState = 4: DoEvents: Loop
    
    Set HTML_Body = IE.document.GetElementsByTagName("Body").Item(0)
    Set HTML_Tables = HTML_Body.GetElementsByTagName("Table")
    Set MyTable = HTML_Tables(2)
    Set HTML_TableRows = MyTable.GetElementsByTagName("Tr")
    
    For Each MyRow In HTML_TableRows
        j = 3
        i = i + 1
        Set HTML_TableDivisions = MyRow.GetElementsByTagName("Td")
        For Each Td In HTML_TableDivisions
            j = j + 1
            RetVal = Td.InnerText
            Cells(i, j) = RetVal
        Next
    Next
    
    Set HTML_Body = Nothing
    Set HTML_Tables = Nothing
    Set MyTable = Nothing
    Set IE = Nothing
End Sub
 
Upvote 0
This code will format the sheet better;

Code:
Sub Test()
    Dim URL As String
    Dim IE As Object
    Dim HTML_Body As Object, HTML_Tables As Object, MyTable As Object
    URL = "http://web1.ncaa.org/d1mfb/Internet/national rankings/IA_teamrush.html"

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate URL
    Do Until IE.ReadyState = 4: DoEvents: Loop
    
    Set HTML_Body = IE.document.GetElementsByTagName("Body").Item(0)
    Set HTML_Tables = HTML_Body.GetElementsByTagName("Table")
    
    Set MyTable = HTML_Tables(1)
    Range("A1") = MyTable.Rows(0).Cells(0).innertext
    Range("B1") = MyTable.Rows(0).Cells(1).innertext
   
    Set MyTable = HTML_Tables(2)
    For Z = 4 To 14
        Cells(1, Z) = MyTable.Rows(0).Cells(Z - 4).innertext
    Next
    
    Range("A1:N1").Font.Bold = True
    
    Range("A1:N1").Font.ColorIndex = 3
    Range("A1:B1").Font.ColorIndex = 5
    
    Set HTML_TableRows = MyTable.GetElementsByTagName("Tr")
    
    For Each MyRow In HTML_TableRows
        j = 3
        i = i + 1
        Set HTML_TableDivisions = MyRow.GetElementsByTagName("Td")
        For Each Td In HTML_TableDivisions
            j = j + 1
            RetVal = Td.innertext
            Cells(i, j) = RetVal
        Next
    Next
    
    Range("A:N").Columns.AutoFit
    
    Set HTML_Body = Nothing
    Set HTML_Tables = Nothing
    Set MyTable = Nothing
    Set IE = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top