Re: Delete Worksheet If It Exists
click debug when the code fails as tell as what line the code failed on and we might be able to help you.
Re: Delete Worksheet If It Exists
click debug when the code fails as tell as what line the code failed on and we might be able to help you.
Re: Delete Worksheet If It Exists
hmm... thats really weird.
Did you just try the example I posted or did you copy and paste the code and button to your actual workbook?
What excel version are you using?
I just cannot understand why even the button didnt work it just has a link to the code....
Re: Delete Worksheet If It Exists
I'm using 2000. Also, I just tried pasting it into my file, no luck.
Re: Delete Worksheet If It Exists
No, that works the first time you do it. The reason that is bugging is because the next time you run the code, the sheet doesn't get deleted so it can't make a sheet called cleaned because it is already there.
Re: Delete Worksheet If It Exists
Interesting; I don't see that syntax in the documentation, but it's neat that it works.
Peculiar that you can't delete the sheet, though. Can you delete it from the Immediate window? From the user interface? Is the sheet or workbook protected?
Re: Delete Worksheet If It Exists
There's no problem deleting it manually, no protection or anything. It just seems that code to delete it doesn't work, but I'm not sure why.
Re: Delete Worksheet If It Exists
I'm not sure I'm following what you're saying. Can you put it in terms a caveman can understand cause that's about my intelligence level.
Re: Delete Worksheet If It Exists
Cavemen are now a protected species under the political correctness code.
The Immediate window is where debug.print outputs appear. You can also type VBA code into the window and execute it. So type,
into it and see if it works.
Do you know how to set a breakpoint and step though code?
Re: Delete Worksheet If It Exists
no. I don't even know what you mean step code.
Re: Delete Worksheet If It Exists
OK, open the VB editor, put the cursor on the line of code that's supposed to delete the worksheet, and press F9 to set a breakpoint. You'll see that the line highlights in some color according to your editor settings.
Then do whatever you do to make the code run. Execution will halt before executing that line. Pressing F8 then executes code one line at a time. It's the process you use for stepping through code.
So the question is, do you hit the breakpoint? And what happens when you execute the line?
Re: Delete Worksheet If It Exists
Also note that putting an apostrophe in front of any lines of code disables that line from running until the apostrophe is removed.
You might want to add like below when debugging:
'On Error Resume Next
'Application.DisplayAlerts = False
ThisWorkbook.Worksheets("Cleaned").delete
'Application.DisplayAlerts = True
'On Error Goto 0
This will not allow the code to "run over" any errors and also display alerts.
Re: Delete Worksheet If It Exists
Hmmm, the code break didn't work unless I did it wrong, but I don't believe I did. Also, I just want to verify that the fact that the code is in my personal workbook wouldn't effect anything, right?
Nevermind, got it (the break) to work. And I just realized that the fact that it's in the personal workbook is exactlly why it's not working. Sorry it took me so long to think about that. Guess I was dropped on my head as a child.
Re: Delete Worksheet If It Exists
So it is working now?
Re: Delete Worksheet If It Exists
Actually, right now I'm trying to figure out how to make it look at the right workbook. If I can't figure it out I'll let you know. Thanks everyone.
Re: Delete Worksheet If It Exists
Hmm. I have no idea how to trigger an event in Personal.xls from another workbook. You could call the routine in Personal from a change event in the workbook of interest, but then you might as well put the rest of the code in there -- plus no one else has your Personal.
Let us know how you do.
Don’t have an account yet? Register yourself now and be a part of our community!