Web table's specified cell import to excel

mikol

New Member
Joined
Nov 22, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
0
I would like to import one cell from a web table to excel.
This is the daily price of copper.
I find for the code and found one part of this.
Please help me to complete the code which imports only the cell in the second row, and second column.
Thx!

VBA Code:
 Dim htm As Object
   Dim Tr As Object
   Dim Td As Object
   Dim Tab1 As Object
   Dim URL As String
   Dim Colstart As Long
   Dim html As Variant
   Dim i As Long
   Dim j As Long
   Dim n As Long
   Dim szoveg1 As String

szoveg1 = "https://www.kabelring.hu/arfolyamok"
   Application.ScreenUpdating = False

     URL = szoveg1

   Set html = CreateObject("htmlfile") 'Create HTMLFile Object
   With CreateObject("msxml2.xmlhttp") 'Get the WebPage Content
      .Open "GET", URL, False
      .send
      html.body.innerHTML = .responseText
   End With

   Colstart = 1 'vízszintes eltolás
   j = 1 'függőleges eltolás
   i = Colstart
   n = 0

   'Loop Through website tables
   For Each Tab1 In html.getElementsByTagName("table")
      With html.getElementsByTagName("table")(n)
        For Each Tr In .Rows
            For Each Td In Tr.Cells
               Munka1.Cells(j, i) = Td.innerText
               i = i + 1 'táblázaton belüli függőleges beolvasás
            Next Td
            i = Colstart
            j = j + 1 'adatok közötti függőleges cellatávolság
          Next Tr
      End With

      n = n + 1
      i = Colstart
      j = j + 1
   Next Tab1

 Application.ScreenUpdating = True
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
A VBA demonstration for starters :​
VBA Code:
Sub DemoReq1()
      Const C = "Alu = "
        Dim T$, L&
    With CreateObject("WinHttp.WinHttpRequest.5.1")
       .Open "GET", "https://www.kabelring.hu/arfolyamok", False
       .setRequestHeader "DNT", "1"
        On Error Resume Next
       .send
        T = .responseText
    End With
        If Err.Number Then Beep: Exit Sub
        On Error GoTo 0
        L = InStr(T, C)
        If L Then MsgBox Split(Mid(T, L + Len(C)), , 2)(0), , C
End Sub
 
Upvote 0
A variation for 'Réz' :​
VBA Code:
Sub DemoReq1v()
      Const C = "Réz = "
        Dim V
    With CreateObject("WinHttp.WinHttpRequest.5.1")
       .Open "GET", "https://www.kabelring.hu/arfolyamok", False
       .setRequestHeader "DNT", "1"
        On Error Resume Next
       .send
        V = Split(.responseText, C)
    End With
        On Error GoTo 0
        If IsArray(V) Then If UBound(V) > 0 Then MsgBox Split(V(1), , 2)(0), , C
End Sub
 
Upvote 0
Solution
A variation for 'Réz' :​
VBA Code:
Sub DemoReq1v()
      Const C = "Réz = "
        Dim V
    With CreateObject("WinHttp.WinHttpRequest.5.1")
       .Open "GET", "https://www.kabelring.hu/arfolyamok", False
       .setRequestHeader "DNT", "1"
        On Error Resume Next
       .send
        V = Split(.responseText, C)
    End With
        On Error GoTo 0
        If IsArray(V) Then If UBound(V) > 0 Then MsgBox Split(V(1), , 2)(0), , C
End Sub
Thanks a lot! I like it!
And could change the messagebox to write data to cell? For example Sheet1, A1?
I tried with ".Range", but I didn't get good solution.

THX!
 
Upvote 0
Thanks a lot! I like it!
And could change the messagebox to write data to cell? For example Sheet1, A1?
I tried with ".Range", but I didn't get good solution.

THX!
Maybe?

VBA Code:
Sub DemoReq1v()
      Const C = "Réz = "
        Dim V
    With CreateObject("WinHttp.WinHttpRequest.5.1")
       .Open "GET", "https://www.kabelring.hu/arfolyamok", False
       .setRequestHeader "DNT", "1"
        On Error Resume Next
       .send
        V = Split(.responseText, C)
    End With
        On Error GoTo 0
        Munka1.Range("A2").Value = Split(V(1), , 2)
        'If IsArray(V) Then If UBound(V) > 0 Then MsgBox Split(V(1), , 2)(0), , C
End Sub
 
Upvote 0
After taking a quick look, probably . . .

VBA Code:
If IsArray(V) Then If UBound(V) > 0 Then Munka1.Range("A2").Value = Split(V(1), , 2)(0)
 
Upvote 0

Forum statistics

Threads
1,223,634
Messages
6,173,477
Members
452,516
Latest member
archcalx

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