Sub DOWNLOAD_6_greyhounds()
Sheets("APP").Activate
Application.ScreenUpdating = False
DoEvents
''''''''''''''''''''''''''''''''''''''''CLEAR 12 PAGES OF DATA''''''''''''''''''''''''''''''''''''''''
For d1 = 1 To 6
With Sheets("TRAP" & d1)
.Range("A2:M200").ClearContents
End With
With Sheets("T" & d1 & "_DL")
.Columns("A:M").AutoFilter
.Range("A:A").ClearContents
End With
Next d1
''''''''''''''''''''''''''''''LOAD ALL 6 WEB PAGES AND CLICK 100 ROWS, ALSO GET NUMBER OF PAGES''''''''''''''''''''''''''''''''''''''''
Dim ie(6) As Object
Dim Doc(6) As Object
For i = 1 To 6
Set ie(i) = CreateObject("InternetExplorer.Application")
With ie(i)
.Visible = True
.Height = 200
.Width = 200
.Left = 900
.Top = 80
.Navigate "http://www.gbgb.org.uk/RaceCard.aspx?dogName=" & Range("'dogs'!$B$" & i + 1).Value
Do While ie(i).Busy: DoEvents: Loop
Do While ie(i).readyState <> 4: Loop
End With
Set Doc(i) = ie(i).document
On Error Resume Next
Doc(i).getElementById("ctl00_ctl00_mainContent_cmscontent_DogRaceCard_lvDogRaceCard_ctl00_ctl03_ctl01_PageSizeComboBox_Input").Focus
Application.SendKeys "100{RETURN}"
Do While ie(i).Busy: DoEvents: Loop
Do While ie(i).readyState <> 4: Loop
On Error Resume Next
If IsError(Doc(i).getElementsByClassName("rgWrap rgInfoPart")(0).getElementsByTagName("strong")(0).innerText) Then
nofpages = 1
Else
nofpages = Application.Ceiling(CLng(Doc(i).getElementsByClassName("rgWrap rgInfoPart")(0).getElementsByTagName("strong")(0).innerText) / 100, 1)
End If
Range("'APP'!$F$" & i + 9) = nofpages
Range("'APP'!$d$" & i + 9) = "web page loaded, downloading"
Application.ScreenUpdating = True
DoEvents
Application.ScreenUpdating = False
Next i
''''''''''''''''''''''''''''COPY DATA FROM WEB PAGES, PASTE THE DATA AND CLICK PAGE 2 ON INTERNET IF NEEDED''''''''''''''''''''''''''''
For y = 1 To 6
ie(y).ExecWB 17, 0
ie(y).ExecWB 12, 2
Sheets("T" & y & "_DL").Select
Range("a1").Select
ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
Application.CutCopyMode = False
If Range("'APP'!$F$" & y + 9) > 1 Then
Set Doc(y) = ie(y).document
Doc(y).getElementsByClassName("rgPageNext")(0).Click
Else
ie(y).Quit
End If
Range("'APP'!$d$" & y + 9) = "complete"
Next y
Call filter_and_copy 'FILTER THE DATA AND CLEAR IN OTHER SHEETS AND PASTE ON NEW SHEET''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''TURN OFF AUTO FILTER AND CLEAR DATA'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For dd = 1 To 6
With Sheets("T" & dd & "_DL")
.Columns("A:M").AutoFilter
.Range("A:A").ClearContents
End With
Next dd
'''''''''''''''''''''''''''''''''''COPY PAGE 2'S IF THEY EXIST AND PASTE DATA''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For q = 1 To 6
If Range("'APP'!$F$" & q + 9) > 1 Then
ie(q).ExecWB 17, 0
ie(q).ExecWB 12, 2
Sheets("T" & q & "_DL").Select
Range("a1").Select
ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
Application.CutCopyMode = False
ie(q).Quit
Else
End If
Next q
Call filter_and_copy 'FILTER THE DATA AND CLEAR IN OTHER SHEETS AND PASTE ON NEW SHEET''''''''''''''''''''''''''''''''''''''''''''''''
Sheets("APP").Activate
Application.Run "CHART_DATA"
End Sub
Sub filter_and_copy()
Dim sht As Worksheet
Dim LastRow As Long
For sh = 1 To 6
With Sheets("t" & sh & "_DL")
.Columns("A:M").AutoFilter
.Range("$A$1:$M$2000").AutoFilter Field:=13, Criteria1:="<>*error*", Operator:=xlAnd
.AutoFilter.Range.Offset(1, 2).Copy
End With 'add date wron into formula to filter out'and check the track matches in the formula
Set sht = ThisWorkbook.Worksheets("TRAP" & sh)
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1
With Sheets("TRAP" & sh)
.Range("A" & LastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
Next sh
End Sub