Vba: extract a single data from a table

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I succeeded to import an entire table from a web page.

But my need is importing just a single data and writing it in Worksheets("General").Range("A1")

The table has 27 columns and 21 rows: how can I import the value with the following coordinates:

column 11
row 4


Code:
Dim tbls, tbl, trs, tr, tds, td, r, c

    Set tbls = IE.document.getElementsByTagName("table")
    For r = 0 To tbls.Length - 1
        Debug.Print r, tbls(r).Rows.Length
    Next r

    Set tbl = IE.document.getElementsByTagName("table")(8)
    Set trs = tbl.getElementsByTagName("tr")

    For r = 0 To trs.Length - 1
        Set tds = trs(r).getElementsByTagName("td")
        
        If tds.Length = 0 Then Set tds = trs(r).getElementsByTagName("th")

        For c = 0 To tds.Length - 1
            Worksheets("General").Range("A1").Offset(r, c).Value = tds(c).innerText
        Next c
    Next r


Thank's in advance.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I dont know how big your table is so something like:

=INDEX(A1:Z100,4,11)
 
Upvote 0
Hello everybody.

I succeeded to import an entire table from a web page.

But my need is importing just a single data and writing it in Worksheets("General").Range("A1")

The table has 27 columns and 21 rows: how can I import the value with the following coordinates:

column 11
row 4


Code:
Dim tbls, tbl, trs, tr, tds, td, r, c

    Set tbls = IE.document.getElementsByTagName("table")
    For r = 0 To tbls.Length - 1
        Debug.Print r, tbls(r).Rows.Length
    Next r

    Set tbl = IE.document.getElementsByTagName("table")(8)
    Set trs = tbl.getElementsByTagName("tr")

    For r = 0 To trs.Length - 1
        Set tds = trs(r).getElementsByTagName("td")
        
        If tds.Length = 0 Then Set tds = trs(r).getElementsByTagName("th")

        For c = 0 To tds.Length - 1
            Worksheets("General").Range("A1").Offset(r, c).Value = tds(c).innerText
        Next c
    Next r


Thank's in advance.

I've made some steps forward in this job.

Now, in this table I've to look for a single data (example: "AA123"). This data is located for sure in the table, is univocal inside the entire table, is always located in the column 3.
I need to identify the row where it is located, and then I've to grasp the data located in the same row but four column toward the right: so, if "AA123" is located in row 5 (and therefore column 3), I've to grasp the data located in row 5 and column 7 (3+4).
The grasped data has to be written in Worksheets("General").Range("A1").

How can I perform the task?
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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