+ Reply to Thread
Results 1 to 8 of 8

Problem with adding sheet

  1. #1
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Problem with adding sheet

    Hi,

    A part of the macro I wrote adds a new sheet to the active workbook. Until now, the code was working fine, but today I encountered the error message "That Command cannot be used on multiple selections", while trying to run the simple code:
    Please Login or Register  to view this content.
    Please note that the workbook is not protected, and multiple sheets are not selected. I have also tried this:
    Please Login or Register  to view this content.
    and this:
    Please Login or Register  to view this content.
    but none works.

    I have realized that this error happens only when the other part of the macro runs the following code:
    Please Login or Register  to view this content.
    So when the SaveCopyAs code has not been run, I don't encounter any problem with adding sheets.

    I cannot understand why this error happens, because before even when the code SaveCopyAs was ran I did not have any problem with adding sheets, and since then I have not changed anything about this part of the code where it adds new sheets.

    Somewhere on the web somebody suggests using the following code:
    Please Login or Register  to view this content.
    before the add code, but it doesn't solve my problem. (I assume because my problem is not that multiple sheets are selected, because in the title bar I see no [Grouped] sign.)

    Note that I am using Excel 2010.

    P.S: After running the SaveCopyAs code mentioned above, I also cannot add sheets manually via Excel.


    By the way, I have no idea why, but my thread keeps on vanishing without any notice, and therefore I have to keep on reposting it

  2. #2
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Problem with adding sheet

    Bump no response

  3. #3
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Problem with adding sheet

    Bump no response

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Problem with adding sheet

    Hi Mayda,

    It will be somewhat difficult to diagnose with seeing the entire script or scripts that are running. It would be most helpful if you post your code, or even a sample of the workbook that is giving you a problem.

    You mention another code (the SaveAsCopy code) possibly interfering. In the past, I have seen circumstances where as a workbook grew in size, some code would throw errors because a previous procedure had not yet finished before the next procedure was called. I know it's a long shot, but it's something to consider.

  5. #5
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Problem with adding sheet

    Hi BigBas,

    First of all, thank you for your interest, it is very much appreicated!

    I refrained from sharing the workbook, because to run the macros, the user needs to perform several complicated operations, otherwise the macros won't run (this is the protection I built in deliberately to prevent users from running the macros without performing the necesarry operations); therefore I think it would be very hard for you to run the macro for replicating the error I'm facing.

    If you just wanted to take a look at the code, I would have appreciated that as well, however, I think it would take an awful lot of time to grasp the whole codes, since, there are 18 Modules, each containing very long codes; so it could take days to understand what's going on.

    Anyway, I was just examining my code, and after some trials, I have found which line of code generates the problem!!!!
    The problem is generated by a line (actually two lines) of code, that deletes some worksheets.

    Let me elaborate:
    The lines of code that cause the error LATER are sheet deleting operations.
    There are 4 total sheet deleting operations that the code runs, but interesetingly only two of them cause the problem!

    The following two lines of code does not cause any problem
    Please Login or Register  to view this content.

    I have realized that only when I run the following two lines of code, I encounter the error [b]LATER ON[/], when the macro is trying to add the sheet:
    Please Login or Register  to view this content.
    I hereby once more would like to emphasize that running these two codes does NOT INSTANTLY cause an error, in other words, these two llines of code is being run without any error. However, after I run this two lines of code, I encounter the error LATER, when I run the sheet adding code, which is this simple line of code:
    Please Login or Register  to view this content.

    Note that MonthToDelete and MonthToDelete_A are string variables, that use some function to return a month name (i.e., January, February etc...) MonthToDelete_A returns the monthname at MonthToDelete and a dot and the letter a. For Example, if MonthToDelete returns the string "January", than MonthToDelete_A returns "January.a"


    I think the solution is very close, please help me find it

    Cheers,
    Gokalp

  6. #6
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Problem with adding sheet

    Bump no response

  7. #7
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Problem with adding sheet

    Bump no response
    If I have helped, Don't forget to add to my reputation (click on the star icon below the post).
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved).
    Use code tags when posting your code.

  8. #8
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Problem with adding sheet

    Bump no response

+ 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