+ Reply to Thread
Results 1 to 2 of 2

Use a variable based on a cell in a WebQuery

  1. #1
    Registered User
    Join Date
    06-10-2019
    Location
    California, USA
    MS-Off Ver
    Office 365
    Posts
    19

    Use a variable based on a cell in a WebQuery

    Hello,

    I'm using a webquery to pull data down to a table in Excel. The query has two hard coded dates in it, but I want to replace them with values stored in cell on another tab in the same workbook. The idea is I can change the dates in the cells, then refresh the query to get new data from the new dates. Here is the webquery I'm using with the hard coded dates.

    Please Login or Register  to view this content.
    The parts I want to replace with references to cells are:

    Please Login or Register  to view this content.
    And...

    Please Login or Register  to view this content.
    I'd like the first one to reference cell A1 (which contains a date, such as 04/16/2023) and the second one to reference cell A2 (which contains a date, such as 04/30/2023).

    I've tried to name the cells, and use this instead of the hard coded date:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    ...but I keep getting errors in the webquery. So, I then created three new cells for each date, using the following code:

    Please Login or Register  to view this content.
    I named each cell, such as WeekStartMM, WeekStartDD, WeekStartYY and PeriodEndMM, PeriodEndDD, PeriodEndYY. Then updated my webquery as follows:

    Please Login or Register  to view this content.
    Now I get an error that states Conversion failed when converting date and/or time from character string.

    Any help would be much appreciated!

    Thanks,

    Mr Z.
    Last edited by Mr. Z; 05-03-2023 at 10:50 AM.

  2. #2
    Registered User
    Join Date
    06-10-2019
    Location
    California, USA
    MS-Off Ver
    Office 365
    Posts
    19

    Re: Use a variable based on a cell in a WebQuery

    With many google searches and trial and error, I was able to find a solution.

    Using this formula was step 1:

    Please Login or Register  to view this content.
    I named two cells WeekStart and PeriodEnd in my workbook. But the values of those cells needed to be in a formula of
    Please Login or Register  to view this content.
    and the CELLREF was another cell where I actually enter the date. This allowed me to enter a date in one cell, which was converted to text in another cell that was used in the webquery.

    Just thought I'd share my solution in case anyone else ever ran into this problem. I'm not sure if my solutions is the most elegant, but it does work!

    Mr Z.

+ 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. Changing URL based on date for WebQuery
    By echoz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2022, 10:40 AM
  2. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  3. [SOLVED] [xl2010] Pass Variable to Webquery Parameter in macro?
    By Dewy1425 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2012, 05:10 PM
  4. Replies: 2
    Last Post: 07-24-2012, 11:47 AM
  5. webquery from hyperlink in cell via VBA
    By jamiepullen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2008, 03:32 PM
  6. Webquery via VBA with variable date
    By Maurice in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-11-2007, 01:47 PM
  7. how to make webquery based on cell
    By josvanbil in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 12-02-2005, 07:10 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