Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a sample method to get you going</p> <p>Based on a few assumptions</p> <ul> <li><p>Workbook contains a Sheet to hold query data called "Query" </p></li> <li><p>Workbook contains a Sheet to put the data in called "AllData"</p></li> <li><p>All old data is removed on running the macro</p></li> <li><p>I think you need to include Table 7 in the qyuery</p></li> <li><p>Pages to process is hard coded as <code>For Pg = 1 To 1</code> , change this to suit </p></li> </ul> <p>.</p> <pre><code>Sub QueryWebSite() Dim shQuery As Worksheet, shAllData As Worksheet Dim clData As Range Dim qts As QueryTables Dim qt As QueryTable Dim Pg As Long, i As Long, n As Long, m As Long Dim vSrc As Variant, vDest() As Variant ' setup query Set shQuery = ActiveWorkbook.Sheets("Query") Set shAllData = ActiveWorkbook.Sheets("AllData") 'Set qt = shQuery.QueryTables(1) On Error Resume Next Set qt = shQuery.QueryTables("Liebermans") If Err.Number &lt;&gt; 0 Then Err.Clear Set qt = shQuery.QueryTables.Add( _ Connection:="URL;http://www.liebermans.net/productlist.aspx?id=7759&amp;page=1", _ Destination:=shQuery.Cells(1, 1)) With qt .Name = "Liebermans" .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End If On Error GoTo 0 i = InStr(qt.Connection, "&amp;page=") ' clear old data shAllData.UsedRange.ClearContents shAllData.Cells(1, 1) = "Title" shAllData.Cells(1, 2) = "Artist" shAllData.Cells(1, 3) = "Type" shAllData.Cells(1, 4) = "Paper Size" shAllData.Cells(1, 5) = "Image Size" shAllData.Cells(1, 6) = "Price" shAllData.Cells(1, 7) = "Quantity" m = 0 ReDim vDest(1 To 10000, 1 To 7) For Pg = 1 To 1 ' Query Wb site qt.Connection = Left(qt.Connection, i + 5) &amp; Pg qt.Refresh False ' Process data vSrc = qt.ResultRange n = 2 Do While n &lt; UBound(vSrc, 1) If vSrc(n, 1) &lt;&gt; "" And vSrc(n - 1, 1) = "" Then m = m + 1 vDest(m, 1) = vSrc(n, 1) End If If vSrc(n, 1) Like "Artist:*" Then vDest(m, 2) = Trim(Mid(vSrc(n, 1), 8)) If vSrc(n, 1) Like "Type:*" Then vDest(m, 3) = Trim(Mid(vSrc(n, 1), 6)) If vSrc(n, 1) Like "Paper Size:*" Then vDest(m, 4) = Trim(Mid(vSrc(n, 1), 12)) If vSrc(n, 1) Like "Image Size:*" Then vDest(m, 5) = Trim(Mid(vSrc(n, 1), 12)) If vSrc(n, 1) Like "Retail Price:*" Then vDest(m, 6) = Trim(Mid(vSrc(n, 1), 14)) If vSrc(n, 1) Like "Quantity in stock:*" Then vDest(m, 7) = Trim(Mid(vSrc(n, 1), 19)) n = n + 1 Loop Next ' Put data in sheet shAllData.Cells(2, 1).Resize(m, 7) = vDest End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload