Ok. So i got the web query to query all the numbers I want and got it to pull some of the data i wanted. Figured out that the website sorts the files randomly each time I query it. So the order I get the data in is different everytime. I initially tried to pull the form# (B4) from the first line of the table and the date (G4) from that same row, but now i need to have it sort or find the file # and if copy it and the date it corresponds to. Tried a few different routes, but getting errors. Ill post the code I have so far.
Option Explicit
Sub Macro1()
Dim URL As String
Dim qt As QueryTable
Dim lastRow As Long
Dim apiNumber As Range
URL = "http://www.pangaeadata.com/OCC_FilesDisplay.aspx?api=3507124329"
With Sheet3
If .QueryTables.Count = 0 Then
Set qt = .QueryTables.Add(Connection:="URL;", Destination:=.Range("A1"))
With qt
.Name = "query"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
End With
Else
Set qt = .QueryTables(1)
End If
End With
With Sheet1
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Each apiNumber In .Range("A2:A" & lastRow)
qt.Connection = "URL;" & URL & "&apiNumber=" & apiNumber.Value
qt.Refresh BackgroundQuery:=False
apiNumber.Offset(, 1).Value = Sheet3.Range("B4")
apiNumber.Offset(, 2).Value = Split(Sheet3.Range("G4"), " ")(0)
DoEvents
Next
End With
End Sub
This is the format I have the data being pulled to a worksheet the way I want it.
1.jpg
This is the format the data is queried into excel
2.jpg
If I could get some help on pulling the dates for the files in an hierarchy (I want form#1002A(Col B) date first (Col G), if form#1002A doesn't exist then I want the form#1001A date, and if form#1001A/1002A doesnt exist yet I want the date for form#1000)
Bookmarks