+ Reply to Thread
Results 1 to 6 of 6

Update Macro/VBA with a Reference to a Cell in Workbook

  1. #1
    Registered User
    Join Date
    07-16-2015
    Location
    Miami
    MS-Off Ver
    2013
    Posts
    3

    Update Macro/VBA with a Reference to a Cell in Workbook

    Hello All,

    I have a decent understanding of excel. Notwithstanding, I am still a bit of a novice when it comes to VBA.

    Here is my dilemma:
    In an attempt to automate a query within one of my workbooks I recorded a simple macro to run/update said query. However, there is an issue... my query was setup in a way that always requires the end user to update the date range within the query. For example, when I want to update my data for the month of August 2015 I need to update the date range to 201508, which equals August 2015 in SQL language. So by default my recorded macro has a reference to a specific date for the query update, in this case 201508. I need to be able to update this date by simply referencing a cell in my workbook (let's say cell A1 on the worksheet tab) which will be the point of reference for my macro's date range. So if someone wants to see this information for September 2015 they can type in 201509 in a cell and run the macro for a quick update. I haven't decide on whether the macro will run when a date range is enter in the cell or if there will be a button. Regardless, any one have any ideas on how I can go about making changes to the below string to make this happen?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update Macro/VBA with a Reference to a Cell in Workbook

    So I'd think you replace this snippet:
    Please Login or Register  to view this content.
    ....with something like this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    07-16-2015
    Location
    Miami
    MS-Off Ver
    2013
    Posts
    3

    Re: Update Macro/VBA with a Reference to a Cell in Workbook

    Hey JBeaucaire,

    I gave this a shot but I got a run-time error "Object variable or With block variable not set". Any thoughts on how I can fix this issue?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update Macro/VBA with a Reference to a Cell in Workbook

    Just a guess that cell A2 doesn't have a List object?

  5. #5
    Registered User
    Join Date
    07-16-2015
    Location
    Miami
    MS-Off Ver
    2013
    Posts
    3

    Re: Update Macro/VBA with a Reference to a Cell in Workbook

    Sorry for the delay but I just figured it out. The error occurred because I built the macro while on the query tab, sheet2. The query list is literally my table on sheet2. The problem was I was executing the macro, after updating the date, in sheet1 which is not where my table is stored. So I made a reference to select sheet2 and the macro works like a charm. Can't thank you enough for the help on this! I should have came here 3 weeks ago instead of trying to do this all on my own. Thanks again!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update Macro/VBA with a Reference to a Cell in Workbook

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Replies: 0
    Last Post: 07-21-2015, 02:35 AM
  2. Macro to Update PowerPivot Using Cell Reference
    By thatsbadass_com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2014, 03:30 PM
  3. Replies: 2
    Last Post: 06-21-2013, 08:59 PM
  4. Macro/VBA to automatically update one workbook from another separate workbook
    By rramoutar7 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-20-2013, 07:34 AM
  5. [SOLVED] Macro to open workbook and go to specific worksheet based on cell reference
    By ajmartin17 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2013, 10:44 AM
  6. Replies: 2
    Last Post: 05-01-2009, 07:06 PM
  7. Need to keep Cell reference after update
    By bmind in forum Excel General
    Replies: 2
    Last Post: 04-08-2009, 09:55 PM

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