+ Reply to Thread
Results 1 to 26 of 26

Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

  1. #1
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Hello all. I'm trying to do a little clean-up on a workbook I created a few months ago with the help of this site. The first issue I hope to resolve is to modify the code to delete the sheet named "False" (or never create it) when someone selects the "Cancel" button in the prompt for adding a new asset. I'll post this section of the code below. It won't let me upload the workbook, as it's just over 5MB - the basic workbook is only 2 sheets and 4 buttons for macros. If there's an easy way to decrease the workbook size, that information would also be appreciated. I could then upload it. Thanks in advance for any help you all might could lend!


    ['Create new tab - copy "Blank_Form" template
    Sub NewTab()
    Application.ScreenUpdating = False
    Dim sName As String
    Dim wks As Worksheet
    Sheets("Blank_Form").Visible = True
    Worksheets("Blank_Form").Copy After:=Sheets(Worksheets.Count)
    Set wks = ActiveSheet
    Do While sName <> wks.Name
    sName = Application.InputBox _
    (Prompt:="Enter Asset Number.")
    On Error Resume Next
    wks.Name = sName
    On Error GoTo 0
    Loop
    Set wks = Nothing
    Sheets("Blank_Form").Visible = xlSheetVeryHidden
    Application.ScreenUpdating = True
    End Sub]
    Last edited by Kenny Blackwell; 08-27-2015 at 10:46 AM.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Add this to your cancel button click code
    Please Login or Register  to view this content.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    I tried entering exactly that between the following, but to no avail:

    [On Error GoTo 0
    Loop]

    Can you tell me where should it be inserted? Is the section referencing "errors" essentially the instructions for when Cancel is selected?

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    I would add
    Please Login or Register  to view this content.
    before your End Sub line.
    The
    Please Login or Register  to view this content.
    should be just after the Sub Title or variable declarations (Dim As)
    The
    Please Login or Register  to view this content.
    should be added just after the sheets delete line and before End Sub.
    The Application.DisplayAlerts True/False lines are optional. When you delete a sheet in excel you will get a message asking if you are sure you want to delete the sheet(s). The display alerts = false keeps this from happening.

  5. #5
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    That perfectly resolves the issue for when they select Cancel. However, when they enter a valid asset number, it now encounters a run-time error because the "False" sheet doesn't exist. Is there a way to create an IfThen line that ignores the instructions to delete when a "False" sheet doesn't exist?

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Try adding
    Please Login or Register  to view this content.
    Just before the
    Please Login or Register  to view this content.
    Line.
    If that doesn't work, here is the If/Then code
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    I was just about to post that I figured out a solution; your proposal was exactly what I came up with. As is usually the case, however, one solution brings light to a new, unforeseen problem. If the user selects Cancel, it takes them to one of the pre-existing sheets. I want it to stay on the Home page if they select Cancel. But if a new asset is created (a number is entered into the Input Box and OK is selected), I want it to take them to the newly-created sheet. I'm sorry to not be able to attach the workbook to make this easier to visualize. If you can tell me some way to reduce the file size, I'll gladly upload it.

  8. #8
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    That would be
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    If I'm not mistaken, that will activate the "Home" sheet whether they create a new worksheet or not, right? If I'm correct, I only want it to remain on the "Home" sheet if they cancel the Input Box for a new asset. Here's what my code now looks like. I apologize for posting incorrectly the first time. It's been a while since I've been on here. I'm also attempting to attach a screenshot so you can get a visual of this workbook. It ends up being several worksheets, all summarized on the "Home" sheet. If they select Cancel on the Input Box, I want them to stay right there on the Home sheet. By the way, this workbook supports multiple ongoing projects in the TX area, so extra thanks for the help!

    ScreenShot_Rentals.PNG

    Please Login or Register  to view this content.
    Last edited by Kenny Blackwell; 08-27-2015 at 12:05 PM.

  10. #10
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Ah Ha! I thought you were using a Cancel Button. Now I see that it is an input box. That changes things a bit..
    Please Login or Register  to view this content.
    You're very welcome for the help.

  11. #11
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Ok, just got back from lunch and plugged this in. Is there somewhere specific it needs to land? I'm getting a Compile Error: Argument Not Optional. After closing the prompt, it has the text "InputBox" highlighted in blue.

  12. #12
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Is there a number after the InputBox....Like InputBox1 or something? If so, add the number after InputBox in the code with no space.

  13. #13
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    I don't think so. None of the code above it references a number, and it's the only Input Box I'm using in the workbook.. Beyond looking at it in VB, is there another way to find out if there's a number suffix?

  14. #14
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    OK, I was way off. I was thinking UserForm type stuff. I now know that you are using a "popup" input box from the code itself. I'm working on it, give me a few.

  15. #15
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Here we go, give this a shot and let me know how it goes. Not sure what your home page is so I used Blank_Form in the code...
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Whoa.. No Sir, unfortunately this wasn't the "fix." The first thing I notice is that code isn't running all the way through. When I enter a number and select OK, it creates a new sheet named "Blank_Form (II)" and doesn't make the original "Blank_Form" very hidden again. The "Blank_Form" is my template for creating the new sheets. I don't want users being able to access it and change it, so I made it very hidden until the new worksheet is being created. When a new sheet is being created, it makes it visible just long enough to copy it and then puts it back out of reach. As far as the naming goes, it's not using the Input Box to name the sheet. When I select Cancel, it also creates a "Blank_Form (II)." Either way, it stays on the "Home" sheet.


    Again, I really wish I could attach the workbook. I know it would make it easier for you to diagnose. Let me know what other information I haven't provided or made clear and I'll do my best to clarify. Thanks again for all the help.

  17. #17
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    So there is an actual sheet called "Home"?

  18. #18
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Yes Sir! If you can see the photo I dropped in earlier it'll at least give you a little idea about how this is laid out. The only way I was able to see it was from outside the thread, where you're looking at all the different threads. There's 1 "Home" sheet and the rest are for all the assets. All of the basic info from the assets are summarized on the "Home" sheet.

  19. #19
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Sorry about that, I am unable to see the photo that was in that post, I forgot to mention that.

  20. #20
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    ScreenShot_Rentals.JPG

    Let's see if you can see this one

  21. #21
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Yup, I can see it. I've run into a snag when I try to add my code into yours and haven't figured out how to get it to work yet. But I'm still working on it.

  22. #22
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Okie dokie, think I got it now, give this a shot
    Please Login or Register  to view this content.
    Last edited by gmr4evr1; 08-27-2015 at 06:48 PM. Reason: Added important piece of code that was missing

  23. #23
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Fantastic, Sir! I added one line - to activate the Home page if E2 = False - but it's now working just as hoped! If you're up for it, I've got another opportunity or two I'd like to explore - just a couple more slight tweaks. If so, should a new thread be created or will this one work?

  24. #24
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Well, a new thread would be best as most of us search for posts with zero replies. But, it's up to you. If you create a new one, post the link on this thread for me in case someone sees it before me.

  25. #25
    Registered User
    Join Date
    03-30-2015
    Location
    Charlotte, NC
    MS-Off Ver
    2013
    Posts
    27

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    Roger that. I'll definitely post a link when I have time to get into more of it. Thanks for all your help with this!

  26. #26
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Code Clean-Up: Delete "False" worksheet created when "Cancel" is chosen in Input Box

    No problem, good luck.

+ 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. Requiring input by user to be either "Economy", "Business" or "Club"
    By cmurda in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2014, 08:57 PM
  2. Replies: 2
    Last Post: 04-20-2014, 11:18 AM
  3. Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" not working
    By redders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 03:52 PM
  4. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  5. How do I stop a Macro after "Cancel" is chosen in an input box?
    By c991257 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2007, 02:27 PM
  6. Replies: 7
    Last Post: 05-13-2006, 05:02 PM
  7. [SOLVED] IF(VLOOKUP("MYDATA", MYNAME, 4) = 0, "TRUE", "FALSE")
    By Souris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2005, 01:05 AM

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