+ Reply to Thread
Results 1 to 4 of 4

Adding Loop to Web Query

  1. #1
    Registered User
    Join Date
    02-05-2011
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    31

    Adding Loop to Web Query

    Hi everyone, I'm a complete VBA Beginner and I've come up with some extremely basic code, mainly from the in built macro recorder

    Please Login or Register  to view this content.
    The code first checks whether there is a Y in cell D1 on the "URL" sheet, if there is, it uses the url text in B1 and exports the data from the web page to cell A1 on the sheet called "1".

    I then replicate this code 100 times for the sheet called "2" depending on the the other values like above, except on row 2.

    Can anyone help with a more efficient way of doing this? There must be a way to add a counter to do this in a few lines of code rather than a few hundred?!

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding Loop to Web Query

    I am not sure if you want to loop through column B or D, but this code assumes you want to loop through column B. I also assume that you are testing each column D for "Y".

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-05-2011
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    31

    Re: Adding Loop to Web Query

    Quote Originally Posted by AB33 View Post
    I am not sure if you want to loop through column B or D, but this code assumes you want to loop through column B. I also assume that you are testing each column D for "Y".

    Please Login or Register  to view this content.
    Sorry I don't think I explained it terribly well....

    URL will be in column B1:100, the "Y" in D is a simple formula to just check there is a value in B1:100, it skips running the macro if there is no value. "Y" is just the denotation I have given for when there is a value.

    So there's effectively 100 web queries using the url in B1:B100. These are outputted to a sheet called "1", "2" etc which coincide with the row they are within B1:B100.

    That make sense?

    Thanks for your help

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Adding Loop to Web Query

    If you want to skip blank cells, you can change the code. It is difficult to see what is going on with the code with out seeing the URL. There are 2 separate issues. First, does the code work and collects the right data, and second issue is the output, ie you want to create new sheets for each loop or table? I have added an error trapping line if the URL is wrong. Could you please post your URL with a sample sheet?

    Please Login or Register  to view this content.
    Last edited by AB33; 07-30-2015 at 04:50 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula - adding an IF Query onto vlookup query
    By mra1984 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-06-2013, 05:31 AM
  2. Getting values of one query as parameter to another query in a loop.
    By Kiran2012 in forum Access Tables & Databases
    Replies: 1
    Last Post: 02-28-2013, 11:56 PM
  3. [SOLVED] Loop through list, perform web query and save each query on its own page
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2012, 07:50 AM
  4. loop in combobox for adding new sheets when adding new items
    By tnkcoll in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2012, 08:27 PM
  5. Adding a extra loop after an exisiting loop
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 04-27-2011, 05:51 AM
  6. Web query (loop)
    By JP Romano in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2010, 04:46 PM
  7. Web Query Loop help
    By brandonscott in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2009, 03:57 PM
  8. [SOLVED] Problem adding charts using Do-Loop Until loop
    By Chris Bromley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2005, 09:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1