webquery, filldown, dynamic ranges - help!


New Member
Feb 23, 2013
[HR][/HR]I am new and have searched endlessly for a couple of days to try and figure this out. Thanks in advance for any help and insight...

sheets(1) has two columns; Column A is href links and Column B is FileNo

Macro looks up href links on sheets(1) and utilizes a webquery to pull table information off of href link in sheets(1) and puts data in Sheets(3). The table is constant and will always have columns (A:I) but the rows are dynamic from 4 rows to 100’s of rows…

Using Sheets(3).Range(“A1”).CurrentRegion the table is copied from Sheets(3) to Sheets(2) in Column B

Next, I would like to look up the FileNo in Sheets(1) that corresponds to the Href. Then copy and paste with filldown into Sheets(2) Column A

Essentially the FileNo acts as a unique key for all the data pulled from each Href webquery.

There are multiple Hrefs (4k plus).

The code works and I can get a single FileNo associated correctly on one line of href table data but I can’t filldown dynamically in Sheets(2) Column A

I am using windows7 and excel2010 32bit
Sub Macro2()
a = 1
While Sheets(1).Cells(a, 1) <> ""
urladdress = "URL;" & Sheets(1).Cells(a, 1).Text

With ActiveSheet.QueryTables.Add(Connection:= _
urladdress, Destination:=Range("A1"))
.Name = Right(Sheets(1).Cells(a, 1).Value, 42)
.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 = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False

End With

Dim CopyRange, PasteRange, FileRange As Range
Dim LastRow As Integer
Set CopyRange = Sheets(3).Range("A1").CurrentRegion
Set PasteRange = Sheets(2).Range("B65536").End(xlUp)
CopyRange.Copy PasteRange
LastRow = Sheets(2).Cells(Sheets(2).Rows.Count, "B").End(xlUp).Row
Set FileRange = Range(PasteRange.Address & ":" & "B" & Lastrow).Offset(0, -1)
Sheets(1).Cells(a, 2).Copy Destination:=FileRange

a = a + 1
End Sub
Last edited:

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...