|
-
Jul 10th, 2003, 09:47 AM
#1
Thread Starter
New Member
Deleting Sheets in Excel using VBA
Hello,
I am trying to write some code which will allow me to delete the sheets at the end of a workbook automatically when I run a macro. The macro imports a number of worksheets with data in them and this then populates a spreadsheet. Before doing this, I want the macro to search the workbook and delete any sheets which have been imported before importing the new ones.
The problems I have include:-
the sheets vary in number from one run to the next.
the sheets do not have common names.
Can anyone help?
-
Jul 10th, 2003, 01:43 PM
#2
So you probably know the "WorkSheet ("WorksheetName").Delete" command. As I understand your problem is to determine the WorksheetName or the Index of it.
Since you managed to open these sheets during the run of your VBA-Macro (at least that's the way I understood your post) you could store the names of these sheets at that time!
And if you have the sheets inside the Workbook before the Macro starts, try it with a negative selection. What are the names of the sheets you want to keep, delete all other.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jul 11th, 2003, 03:54 PM
#3
hmmm, just posted a reply on this post which'll be the easiest way to accomplish this:
http://www.vbforums.com/showthread.p...hreadid=253113
Either try as suggested above, or store the worksheets.count number into an numeric variable, call your macro, then loop through the sheets & any which are found to have an index greater than this stored number, you can call the worksheets(i).delete method on...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|