+ Reply to Thread
Results 1 to 9 of 9

Running a Macro but Sheet name changes; leading to DEBUG error

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Running a Macro but Sheet name changes; leading to DEBUG error

    Hello,

    I wanted to know how would you work around the following problem.

    So I have a button on Excel that runs a Macro on my Excel.

    When ever I click on the option to import the Data I am working with into excel, the default sheet name is "Download(1)".

    The line from my macro looks something like this...
    #
    Please Login or Register  to view this content.
    #

    Lets say while Download(1) is still active I go and import the same data again, then the sheet name"Download(1)" changes to Download(2) and so on...

    So if it becomes "Download(2)" I would receive a Debug error because the code has "Download(1)"

    what would I have to do so I never have to worry about the changing number in the parenthesis causing my code to need debugging???

    Please let me know if there is further clarification needed.
    Last edited by alansidman; 11-05-2013 at 06:21 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    Hi Swade,

    If you always download the sheet to the left most sheet it will always be Worksheets(1). The short answer is try to use Sheet Indexes instead of their specific name.

    See:

    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    The last worksheet will be:

    Worksheets(sheets.count)

    Here is an inclusive link about worksheets...

    http://www.cpearson.com/Excel/SheetNameFunctions.aspx
    Last edited by MarvinP; 11-05-2013 at 06:29 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    Does it always put the newest "Download" sheet as the last tab? If so you could reference that last sheet like this:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    I think you are getting the technique.. Read the second link I just put on my last thread.

    I do all the testing in my immediate pane to see if VBA like it or not. Then I copy it into my code.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    How is the code importing the data?
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    Download appears because when your using the website I am working with...there is a button you can click that reads "export to excel"

    So when you click it, excel automatically opens up and then on the first sheet it would read for the sheet name "Download(1)"

    further more lets say I imported data from the website and its sitting in excel as
    "Download(1)" and I minimize it. If I click the button to bring the data again into excel, excel names it "Download(2)" second time around (while I have "Download(1)") in the background.

    To your point MarvinP , The sheet position may solve this issue, So as long as the data appears on the first sheet -in the set of worksheets (position wise), I should be good?

  7. #7
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    Quote Originally Posted by Norie View Post
    How is the code importing the data?
    It's not, I import it from an outside website into excel

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    How do you import it?

    Could you import it to a specific worksheet, perhaps via Data>Web Query?

  9. #9
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Running a Macro but Sheet name changes; leading to DEBUG error

    Quote Originally Posted by Norie View Post
    How do you import it?

    Could you import it to a specific worksheet, perhaps via Data>Web Query?
    No it's imported from a website that gives you the ability to click import

+ 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] Help running SQL Update Via VBA (Missing Operator Debug Error)
    By jo15765 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2012, 09:15 AM
  2. Macro - debug error
    By emptycucumber in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-19-2009, 07:03 AM
  3. pasting data debug error on a sheet with borders
    By Traymond in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-01-2009, 12:46 PM
  4. Error- Running a Macro on a Protected Sheet
    By nacho in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2007, 08:21 PM
  5. [SOLVED] Help with leading Zeros when running Macro
    By bob in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-05-2006, 01:15 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