+ Reply to Thread
Results 1 to 12 of 12

VBA Worksheet select error.

  1. #1
    Registered User
    Join Date
    07-14-2009
    Location
    CT, USA
    MS-Off Ver
    Excel 2016
    Posts
    71

    VBA Worksheet select error.

    Hi, I attached my workbook so you guys can easily take a look.
    In this workbook I have 2 hidden worksheets.

    To start off, you click the Add Week button, put in a date (mm-dd-yy), that brings up the sheet thats named with the date you just put in the text box. (Which happens to be placed in the wrong spot) In that sheet that appears theres a button to "Delete last" which is suposed to delete the last sheet in the worksheet but the new sheet gets placed between the existing charts. Thats my first problem.

    Next, when you hit the delete button, my VBA code is set to make one of the hidden sheets visible so it can delete one of the rows.

    Please Login or Register  to view this content.
    Its fine deleteing the row, but when I go back and select this sheet again I get an error with the selection.

    Please Login or Register  to view this content.
    even though I have the exact same line of code just before and it doesnt give me an error.

    Heres a snipet of the code but you guys can take a look at the actual file for the full thing.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Worksheet select error.

    Welcome to the forum.

    Looks to me like you're trying to select it after just having deleted it.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    07-14-2009
    Location
    CT, USA
    MS-Off Ver
    Excel 2016
    Posts
    71

    Re: VBA Worksheet select error.

    I wrote this last year and havent used excel since so my understanding of the code is less then optimal.

    The Total WO Table does not get deleted, it gets moved then selects the last sheet. But it has Worksheets(Worksheets.Count).Select so it selects the absolute last sheet created which is always one of the datasheets.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Worksheet select error.

    Maybe like this:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-14-2009
    Location
    CT, USA
    MS-Off Ver
    Excel 2016
    Posts
    71

    Re: VBA Worksheet select error.

    Using exactly that I get an error that says "Object variable or With block variable not set" If I try to use the macro a second time after the error, it gives me an error 400.
    Last edited by Mase123y; 07-14-2009 at 02:26 PM.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Worksheet select error.

    Post the workbook with that code that demonstrates the failure.

    EDIT: You will get that error if sName is not found on the surviving sheet. What do you want to do when that happens?

  7. #7
    Registered User
    Join Date
    07-14-2009
    Location
    CT, USA
    MS-Off Ver
    Excel 2016
    Posts
    71

    Re: VBA Worksheet select error.

    The current code deletes the WO Complete chart after the error while my code does not. Im still trying to get the add week macro to add the sheet after the chart but its not working.
    Attached Files Attached Files
    Last edited by Mase123y; 07-14-2009 at 02:51 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Worksheet select error.

    What is the Delete macro supposed to do, exactly?

  9. #9
    Registered User
    Join Date
    07-14-2009
    Location
    CT, USA
    MS-Off Ver
    Excel 2016
    Posts
    71

    Re: VBA Worksheet select error.

    Delete the last data sheet, not the chart. If you could get it to delete the current sheet that the macro button was pressed on that would be great, thats probably what I need to work towards.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Worksheet select error.

    delete the current sheet that the macro button was pressed on
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-14-2009
    Location
    CT, USA
    MS-Off Ver
    Excel 2016
    Posts
    71

    Re: VBA Worksheet select error.

    Deleteing the sheet is fine, its combining everything where Im getting an error. The error I get is when I try to make a sheet visible, Im not trying to delete it and its not getting deleted and its not like you get an error when you try to make a sheet visible thats already visible. But thats what its giving me an error and I dont know why.

    Do you get any errors when you run my original code?

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Worksheet select error.

    There's no need to make the sheet visible to delete it or to operate on its contents.

+ 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