+ Reply to Thread
Results 1 to 5 of 5

Code to reference cell as parameter when pulling data

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    Boston, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Code to reference cell as parameter when pulling data

    Hi,
    I'm trying to design a spreadsheet where th user will enter a few parameters in a sheet and then press a button for a query to pull data.

    I have the first thing done, which is the macro for the data. But don't know how to use the parameters for it.

    My code is:
    Please Login or Register  to view this content.
    So where it says:
    Please Login or Register  to view this content.
    I want to be able to reference a cell in a sheet called "Parameters", for example cell D4,
    the same with:
    Please Login or Register  to view this content.
    I don't want the dates to be fixed but to reference two cells in the "parameter" sheet.

    I tried to do the parameters through the Data section, but because this query can't be shown graphically, microsoft query will not let me use the parameter option in excel.

    Any ideas?
    Any help will be appreciated.

    Thanks.
    Last edited by jaimealvarez; 04-24-2012 at 04:51 PM. Reason: Changed title. Added CODE tags for new user. Please do so yourself in the future.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Code to reference cell as parameter when pulling data

    Quote Originally Posted by jaimealvarez View Post
    Please Login or Register  to view this content.
    I want to be able to reference a cell in a sheet called "Parameters", for example cell D4,
    Something like:
    Please Login or Register  to view this content.
    Quote Originally Posted by jaimealvarez View Post
    Please Login or Register  to view this content.
    I don't want the dates to be fixed but to reference two cells in the "parameter" sheet.
    Like this:
    Please Login or Register  to view this content.
    and similarly for the other date-time.

    You'll also need to ensure that all the strings are properly constructed with start and end double quotes, which I'll leave to you to sort out.
    Last edited by Chippy; 04-24-2012 at 06:14 PM.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    04-24-2012
    Location
    Boston, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Code to reference cell as parameter when pulling data

    Thank you so much! Worked perfect.

  4. #4
    Registered User
    Join Date
    04-24-2012
    Location
    Boston, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Code to reference cell as parameter when pulling data

    I might have jumped of excitement to fast.
    The first part worked great but the part with the dates don't. When I tried to save the code turns red and indicates there is an error. I know it has to be something with the formatting, but can figure out what.
    This is what I have.

    Please Login or Register  to view this content.

    Thanks for the help

  5. #5
    Registered User
    Join Date
    04-24-2012
    Location
    Boston, USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Code to reference cell as parameter when pulling data

    Thanks to Chippy's help I was able to solve this one. the problem was in the formatting of the code. I had an extra ", and also the value had to be formatted differently so that Microsoft Query would be able to use it. Here is the final code I used:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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