Updating a worksheet with scraped webdata

misimiki

New Member
Joined
Sep 13, 2012
Messages
1
Evening all,

First post from a VBA newbie, so thanks in advance for your help.

I have spent the day importing European Soccer League tables into Excel by following the instructions found in Mr Excel's Learn Excel videos #664 and #665 on the YouTube channel. It all worked a treat and was easy to follow.

I even figured out how to rename the worksheets with a short text string that I pulled out of the weblinks that I extracted from video.

I now want to add some functions to each sheet to allow for some statistical analysis of the footy data, which I know how to do.

My question is how can I update the worksheets that I have just created (which I would like to do on a weekly basis) with new data from the same website using VBA rather than simply creating new ones?

I attach the code for those who are not familiar with the videos.

Code:
Sub loopthrough()    Dim WSO As Worksheet
    Set WSO = ActiveSheet


    For Each cell In WSO.Range("D1:D23")
        ActiveWorkbook.Worksheets.Add After:=ActiveSheet
        
        ThisURL = "URL;" & cell.Value
        URLName = Replace(Mid(ThisURL, 42, 20), "/", " ") 'country extracted


        
    With ActiveSheet.QueryTables.Add(Connection:= _
        ThisURL _
        , Destination:=Range("$A$2"))
        .Name = "table"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False


        ActiveSheet.Name = URLName


      End With
      
    Next cell
    
End Sub






Sub GetLinks()
    For Each hl In ActiveSheet.Hyperlinks
        Cells(hl.Parent.Row, 4).Value = hl.Address & "/table"
    Next hl
    


End Sub

There are one or two minor additions to the original code.

I hope that this is clear
Many thanks

michael
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

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