webquery, filldown, dynamic ranges - help!

everfind

New Member
Joined
Feb 23, 2013
Messages
2

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
Sheets(3).Select
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

Sheets(3).Cells.ClearContents
a = a + 1
Wend
End Sub
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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