+ Reply to Thread
Results 1 to 9 of 9

VBA - Delete sheets in activeworkbook

  1. #1
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    VBA - Delete sheets in activeworkbook

    Hello All, i have also posted this at MrExcel because i kind of need a solution fairly quick and i hoped to better my chance by posting at 2 sites.

    http://www.mrexcel.com/forum/excel-q...ml#post3801354
    I am working on a macro which creates a new workbook by copying activeworkbook and while doing so delete some sheets.

    For some reason, i can see that it deletes it, but then it creates it again. In question is highlighted in red font. Can someone point to me what i am doing wrong?

    Please Login or Register  to view this content.
    Last edited by honger; 05-07-2014 at 10:37 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: VBA - Delete sheets in activeworkbook

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    http://www.mrexcel.com/forum/excel-q...eworkbook.html

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Delete sheets in activeworkbook

    Quote Originally Posted by honger View Post
    I am working on a macro which creates a new workbook by copying activeworkbook and while doing so delete some sheets.

    For some reason, i can see that it deletes it, but then it creates it again. In question is highlighted in red font. Can someone point to me what i am doing wrong?
    I don't see any code where you copy the active workbook.

    You open a workbook file and delete Sheet7 in that opened workbook,do other formatting, then save it.

    You then close the workbook that contains the code (not the opened workbook).


    I'm not sure what you want done?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: VBA - Delete sheets in activeworkbook

    sorry i was in rush and i was hoping for a better chance to get a solution... i have modified the first post, does that comply? if not please let me know. thank you

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: VBA - Delete sheets in activeworkbook

    Honger: Yes, it is now in compliance, but please read the link I provided on why it may backfire on you when you post to multiple sites.

  6. #6
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: VBA - Delete sheets in activeworkbook

    Below is the entire code i have.

    It is supposed to copy the open active workbook and saveas in a different location. While doing so i want some sheets to be deleted according to value chosen in combobox3. Everything works but it wont delete that sheet while creating the new workbook. It does delete it, but then it gets created again . I think i know this is happening because when i got rid of the Application.Displayalerts, diaglog box asked to confirm the delete and it deleted the sheet for a second but it recreated it

    Please Login or Register  to view this content.
    Last edited by honger; 05-07-2014 at 10:55 PM.

  7. #7
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: VBA - Delete sheets in activeworkbook

    Quote Originally Posted by alansidman View Post
    Honger: Yes, it is now in compliance, but please read the link I provided on why it may backfire on you when you post to multiple sites.
    i completely understand, i am very new to VBA and was in need of a solution quick...i am also ancxious to figure out this stuff because this is fascinating to me.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Delete sheets in activeworkbook

    You cannot use a worksheet's Code name (Sheet7) to refer to a sheet in another workbook. Sheet code names always refer to the same workbook that contains the code. You can only reference sheets in another workbook by Tab-name or index number.

    This gets the Tab-name of Sheet7 from the original workbook and uses that tab-name to delete the worksheet in the copy.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-07-2013
    Location
    NJ
    MS-Off Ver
    2010
    Posts
    91

    Re: VBA - Delete sheets in activeworkbook

    thank you!!! that worked like a charm!!! you guys are great.

    I am not quite done yet and there is another thing i want to do, so i am going to give it a try now!!

+ 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] ActiveWorkbook.Close closing sheets, but not the window
    By mintymike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2014, 07:36 AM
  2. Different between ActiveWorkbook.Sheet and ActiveWorkbook.WorkSheets
    By Ranjani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2009, 12:56 AM
  3. Macro to delete sheets and saves remaining file does not properly delete module
    By pherrero in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2005, 08:12 PM
  4. Replies: 0
    Last Post: 06-21-2005, 01:05 PM
  5. Replies: 2
    Last Post: 05-07-2005, 12:08 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