Leith, or someone else
-if this should be in a seperate topic let me know and i'll start one-
I've used the code and used it in the macro below. Its a query to retrieve traffic information and then copy selected roads to another part of the sheet. However I need a way to make this loop as there will be more than 1 notification of the same road when it is very busy and i like to see all of them. I will probably be looking at a max of five individual roads, like A1. A12, A14. (not like A1, A2, A3). I've coded for 2 now but i suppose 2 or 5 shouldn't be much of a difference with regard to method of coding.
I also had to use the on error resume next because if it doesn't find anything the macro fails.
Question: How to loop this properly?
Question: Is this a "proper" way and/or can i take shortcuts somewhere?
Sub query()
Dim LastRow As Long
On Error Resume Next
'brings traffic jam data from web to excel
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.nu.nl/pda_sectie.jsp?n=236&c=75", Destination:=Range("A1"))
.Name = "pda_sectie.jsp?n=236&c=75"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "5"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Columns("B:f").Select
Selection.ClearContents
'finds road
Columns("A:A").Select
Selection.Find(What:="File: A10 ", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'finds last row in column C
With ActiveSheet
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
End With
CopyRows ActiveCell, Cells(LastRow, 3).Offset(2, 0)
ActiveCell.ClearContents
'next road
Columns("A:A").Select
Selection.Find(What:="File: A35 ", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
With ActiveSheet
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
End With
CopyRows ActiveCell, Cells(LastRow, 3).Offset(2, 0)
ActiveCell.ClearContents
End Sub
Bookmarks