+ Reply to Thread
Results 1 to 6 of 6

Macro Refresh Button: Run-time Error 1004

  1. #1
    Registered User
    Join Date
    03-26-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Macro Refresh Button: Run-time Error 1004

    Hi,

    Lucky for me, I have been tasked with 'fixing' a button within a rather large and complex spreadsheet. The button merely refreshes a macro, which pulls data from a specific column in a separate worksheet - I'll call this Column A. The refresh works fine as long as a cell in Column A is selected when I click the button. However, if a cell outside of Column A is selected, and I try to refresh, I receive a VBA run-time error 1004 with the narrative 'Application-defined or object-defined error' (which I presume is indicating a cell within Column A needs to be selected) with the options to End or Debug. As a lot of people use this workbook, keeping a cell in Column A permenantly selected proves a little tricky.

    My question is: can I alter the existing macro/create a new macro so that it doesn't matter whether a cell in Column A is selected?

    All suggestions welcome.
    Last edited by j_henley123; 03-26-2012 at 11:26 AM.

  2. #2
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    462

    Re: Macro Refresh Button: Run-time Error 1004

    might be easier to stick some code in to just select cell A1 when the macro runs?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-26-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro Refresh Button: Run-time Error 1004

    Thanks for that John - I had been wondering if you could select a range. Where exactly should that code be entered into the macro though? When I select to debug, the following narrative is highlighted:
    Please Login or Register  to view this content.
    Apologies for such a simple question - I'm a bit of newbie to macros!
    Last edited by arlu1201; 03-26-2012 at 06:31 AM.

  4. #4
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    462

    Re: Macro Refresh Button: Run-time Error 1004

    If the macro is failing at that piece of code then I would stick the range("A1").select code right above it

    Without seeing the sheet, I can't see why it would need a cell in column A selecting but if that fixes it then fine!
    John

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro Refresh Button: Run-time Error 1004

    Quote Originally Posted by j_henley123 View Post
    Thanks for that John - I had been wondering if you could select a range. Where exactly should that code be entered into the macro though? When I select to debug, the following narrative is highlighted:

    Sheets("SheetX").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False

    Apologies for such a simple question - I'm a bit of newbie to macros!
    J_henley123,

    Welcome to the forum.

    Please ensure that you use code tags while posting any code in your post, however big or small the code might be. This ensures that your code is easier to read and others can easily use it to test your code.

    I have done it for you this time. Please check the forum rules on how to apply them in future.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Registered User
    Join Date
    03-26-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro Refresh Button: Run-time Error 1004

    Johncassell - Brilliant! All solved, cheers.

    Arlu1201 - apologies, I wasn't aware but am now. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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