Excel delete all but one sheet

Содержание

  1. How to Delete Sheets in Excel (Shortcuts + VBA)
  2. Delete Sheets Using Right-Click Options
  3. Keyboard Shortcuts to Delete the WorkSheets
  4. Hybrid Keyboard Shortcut to Delete Sheet
  5. Regular Keyboard Shortcut to Delete Sheet
  6. Legacy Keyboard Shortcut to Delete Worksheets
  7. Deleting the ActiveSheet Using VBA
  8. Deleting the Sheet Without Showing the Confirmation Prompt
  9. Deleting Sheet By Name (If It Exists) Using VBA
  10. Deleting All Sheets Except the Active Sheet Using VBA
  11. Delete All Sheets with a Specific Text String in the Name
  12. Delete All Sheets Except One
  13. Delete All Sheets Except One — Excel
  14. Similar Topics
  15. How To Delete Multiple Sheets — Excel
  16. Vba Code: Delete Entire Row Based On Condition — Excel
  17. Delete Only Selected Item From The Listbox And Listbox Populating Source. — Excel
  18. Userform For Search, Edit, Change And Delete — Excel
  19. Vba — How To Delete Autofiltered Rows Except For The Header? — Excel
  20. How Do You Delete Filtered Rows In An Autofiltered List. The Row. — Excel
  21. How To Delete All Commas From A Spreadsheet? — Excel
  22. What Is The Shortcut For Delete, Shift Cells Up? — Excel
  23. Macro To Zoom To Fit Window, Then Apply That Zoom Factor To Other Sheets — Excel

How to Delete Sheets in Excel (Shortcuts + VBA)

When working with Excel, you spend most of your time on the worksheet (which is the area that has all the cells and everything that happens there).

Working efficiently with Excel also means that you have to work with multiple worksheets within the same workbook.

Excel allows you easily add multiple worksheets in the workbook, at the same time you can also easily delete these worksheets.

In this Excel tutorial, I will show you how to quickly delete worksheets in Excel. I would cover multiple methods such as using keyboard shortcuts, options in the ribbon, and VBA to delete sheets in Excel.

This Tutorial Covers:

Delete Sheets Using Right-Click Options

The easiest way to delete a worksheet in Excel is by using this simple two-click mouse technique.

Suppose, you have a worksheet that has three sheets as shown below, and you want to delete Sheet1.

Below are the steps to do this:

  1. Right-click on the sheet that you want to delete
  2. Click on the delete option
  3. In the prompt that shows up, click on the Delete button

You can also use the above technique on sheets that are not even the active sheet. For example, if I’m currently on Sheet1 and I want to delete Shee3, then I can simply right-click on Sheet3 and delete it.

You can also use the same technique to delete multiple sheets at once.

For example, if I want to delete Sheet2 and Sheet3 in one go, I can hold the control key and click on Sheet2 and Sheet3 one by one (while still holding the control key).

By holding the control key, Excel would allow me to select multiple sheets at one go. Once I’m done selecting the desired sheets, I can leave the control key. now I can right-click on any of the selected sheets tabs, and click on delete.

Keyboard Shortcuts to Delete the WorkSheets

There is not one but two-and-half keyboard shortcuts that you can use to delete worksheets in Excel.

I say two and a half because one of the shortcuts he uses the mouse as well as the keyboard (and is still a faster way to do it)

Hybrid Keyboard Shortcut to Delete Sheet

To delete the selected worksheet or worksheets, right-click and then press the D key on your keyboard.

Personally, I find this a lot faster than just using the mouse to delete a worksheet (as I covered in the above section)

Regular Keyboard Shortcut to Delete Sheet

If you would rather prefer to ditch the mouse and only use the keyboard, the above keyboard shortcut will delete the active sheet or the selected sheets.

You need to press these keys in succession (i.e., one after the other)

While it may look like a slightly longer keyboard shortcut, once you get used to it it’s just as fast as any other technique covered in this tutorial

Legacy Keyboard Shortcut to Delete Worksheets

Like everyone else, Excel also has a past, and it’s not that pretty. I’m talking about the pre-ribbon style era.

For compatibility reasons, Excel still allows some of those old keyboard shortcuts to work in the newer versions. and in many cases, those earlier shortcuts are shorter and better.

Luckily, there is a legacy keyboard shortcut that works to delete worksheets in Excel

Deleting the ActiveSheet Using VBA

When it comes to deleting one sheet, or a couple of worksheets, it’s better to use the above-mentioned methods.

While VBA can automate the process, it’s usefulness comes in when you have to repeat the task multiple times.

As you will see, with VBA you can do a lot more when it comes to deleting worksheets in Excel.

So I’ll take you to more advanced use cases, but before that let’s see how to simply delete the active worksheet using VBA.

Below is the VBA code that will delete the active sheet:

If you’re using it in the immediate window, you can simply use the below line:

When you use the above code to delete the active sheet, Excel would show you a prompt where you would have to click the delete button to confirm the action.

Deleting the Sheet Without Showing the Confirmation Prompt

The confirmation prompt message box is a useful feature that makes sure that you have a chance to cancel the deletion of the sheet in case you have run the code accidentally/erroneously

But if you already know what you’re doing, getting this prompt can be quite irritating.

so here is the VBA code that would make sure that the sheets are deleted but you do not see any confirmation prompt message box.

In the above code, I have set the Application.DisplayAlerts property to false, which means that Excel will not show you any display alerts while the code is running.

It’s also really important to make sure that you turn it back to true at the end of the code to restore the functionality (as you can see I have done in the above code).

Caution: When you set the Application.DisplayAlerts property to false, Excel would simply delete the worksheet and there would be no way to recover it. so I advise you make a backup copy before you use this kind of code.

Deleting Sheet By Name (If It Exists) Using VBA

VBA allows you to automate the process of deleting a specific worksheet (on multiple worksheets) based on the sheet name.

For example, if you have a worksheet with the name ‘Sales’, you can use the below code to delete it:

This code would only delete the sheet that has the name Sales.

It’s useful when you have a workbook with a lot of sheets and you don’t want to sift through all the worksheets find the one with the name sales and delete it manually.

With the above code, it does not matter how many worksheets there are in the workbook it would simply delete the sales worksheet.

And since I have not changed the Application.DisplayAlert property, you will see a prompt where you would have to click the delete button to confirm the duration of the sales sheet.

In case you want to delete multiple sheets based on their name, you can do that as well.

For example, the below code would delete the sheets with the name Sales, Marketing, Finance:

Deleting All Sheets Except the Active Sheet Using VBA

If you have a workbook with multiple worksheets in it, and you want to delete all the worksheets except the active sheet, VBA is probably one of the better methods to do this.

Below is the VBA code that would delete all the sheets except the active sheet in the workbook.

Note that I have said the Application.DisplayAlerts property to falls at the beginning of the code, as I don’t want to see a prompt for every sheet that is deleted.

Delete All Sheets with a Specific Text String in the Name

This is a slightly more advanced use case of using VBA effectively when deleting worksheets.

Suppose you have a workbook with many different worksheets and you want to delete all the worksheets that have a specific text string in them then you can easily do that using VBA.

For example, below I have a workbook where I want to delete all the worksheets that have the text string “Sales” in them.

Below is the VBA code that would do that:

The above code uses the if-then statement to go through all the worksheets in the workbook. It checks the name of all these worksheets and if the name contains the word “Sales”, then that worksheet is deleted.

If you want to change the code and look for any other text string, you can change that in the fifth line of the above code.

Also note that I’ve used an asterisk (*), which is a wild card character, on both sides of the text string that we are looking for in the worksheet name. This ensures that no matter where the string appears in the name of the worksheet, it would still be deleted.

You can also modify the code to make sure that only those worksheets are deleted where the text string appears at the beginning of the worksheet name.

For example, if you want to delete those sheets where the term sales appear at the beginning, use the following code in the fifth line.

Here, I’ve used the wild card character only after the text drink and not before it. This will make sure at while checking the names of the worksheet, only those would satisfy the criteria where the term ‘Sales’ is at the beginning of the name.

So these are some of the methods that you can use when you want to delete sheets in Excel. In most cases, you can easily do this right within the worksheet by using the mouse or the keyboard shortcut.

But in case you have a heavy workbook with a lot of worksheets and you want to quickly delete specific kinds of sheets then you can also use VBA.

I hope you found this tutorial useful.

Other Excel tutorials you may also like:

Источник

Delete All Sheets Except One

Delete All Sheets Except One — Excel

How can I delete all worksheets in a workbook except for one with a given name? The titles of the other worksheets will vary, so I’m not sure how to do it (I only know how to delete based on a name; in this case, I want to always delete all worksheets except for «Main»).

Thanks in advance!

(80% Sale Ends Soon)

Excel VBA Course — From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

(80% Discount Ends Soon!)

Similar Topics

How To Delete Multiple Sheets — Excel

Hi,
I need the necessity do delete a sequence of sheets in my workbook.
If I use this code:

With ActiveWorkbook
If .Worksheets.Count >= 5 Then
For n = 5 To .Worksheets.Count
Worksheets(n).Delete
Next n
End If
End With

I receive a confirmation message box with this message:

«Data may exist in the sheet(s) selected for deletion. To permanently delete the data, press Delete» [DELETE] [CANCEL]

I wish to delete all sheets without receiving any message.

Many thanks in advance for your kind support.

Vba Code: Delete Entire Row Based On Condition — Excel

Still learning VBA — I am trying to delete an entire row based on a condition in one cell in the row. Typically I would just filter on that value and delete the rows, but I am not sure if that is a possibility in VBA code. Can you provide the code if not too complex.

Select Cell A1 if value is 100 delete entire row, else skip to next row. Then loop through each row in the spreadsheet till all rows with selected cell equal to 100 are deleted.

Delete Only Selected Item From The Listbox And Listbox Populating Source. — Excel

I have the below code which deletes all items from a listbox and my excel sheet which is the source for populating that listbox. I am using a option button style for my listbox and the selection style as single .i.e. you can select only one item at one go in the lisbox. I want my macro to delete the selected item from my worksheet .i.e. it’s entire row so that it doesn’t reflect in my lisbox any more. Below is my code :

Thanks a lot for your help in advance.

Userform For Search, Edit, Change And Delete — Excel

How to create a userform that will have button for search, edit, change, delete individual recordings. Also in case of listed results obtained records that could be printed?

Vba — How To Delete Autofiltered Rows Except For The Header? — Excel

Hi,
how do I select (in VBA) all the rows that were filtered out by autofilter (using VBA code) and delete them leaving just header. I just can’t figure out how to select entire rows when the data is filtered.
Thanks for your hints!

How Do You Delete Filtered Rows In An Autofiltered List. The Row. — Excel

When I auto filter a spreadsheet, I can’t figure out how to delete or
eliminate from the sheet the filtered-out rows. So when I refilter the sheet
with new items to get rid of, the old filtered items come back. I’ve tried
copying the range to another file, but I always get all the old data in the
new file.

How To Delete All Commas From A Spreadsheet? — Excel

I have a large spreadsheet in Excel 2007. I am converting it to a .csv file to import in to another program. I need to delete all commas from all data.

When I try to replace all commas (with nothing or with another character), I get the error message «The formula you typed contains an error.»

I have tried various formats (text, general, etc.) and various file types (.xls,.xlsx, .csv) and still get the same error.

What Is The Shortcut For Delete, Shift Cells Up? — Excel

Hi all! Can anyone tell me the shortcut for Delete, Shift cells up? I have checked through Google but could not find the shortcut.

Macro To Zoom To Fit Window, Then Apply That Zoom Factor To Other Sheets — Excel

I have set up a workbook that is sent out to lots of different users. They each keep and use their own copy.

I have set it up so that everything looks OK and is visible on MY screen, but I’m conscious that some users may have different screen sizes, different toolbars set up, and so on, which might make some parts not immediately visible to them.

I have set up an auto-execute macro which automatically sets the zoom factor to best fit, for several of the worksheets, and this works fine.
Here’s the code that does it.
Code:

By repeating this code for each worksheet, I can make each one be zoomed just right.

However, the file contains 8 sheets that are all identically laid out, except the number of rows is different.
What I want to do is go to the worksheet that has the largest number of rows (it’s always the same worksheet, so I know which one it is), set the zoom factor for THAT worksheet (which I can do, and it always has the same number of rows), and then take THAT zoom factor, whatever it is — and it will vary depending on the user — and apply that to the other worksheets that have a similar layout.

I could just go through each worksheet and zoom it automatically, but that would mean that some of the sheets looked very large, others very small, and I’d like them to have a consistent appearance.
I could also specify a range on each worksheet that was similar to the appropriate range on the longest worksheet, and zoom that automatically, but that’s not ideal either, because some of the row heights vary from sheet to sheet, and again I’ll end up with different font sizes.

Источник

When working with Excel, you spend most of your time on the worksheet (which is the area that has all the cells and everything that happens there).

Working efficiently with Excel also means that you have to work with multiple worksheets within the same workbook.

Excel allows you easily add multiple worksheets in the workbook, at the same time you can also easily delete these worksheets.

In this Excel tutorial, I will show you how to quickly delete worksheets in Excel. I would cover multiple methods such as using keyboard shortcuts, options in the ribbon, and VBA to delete sheets in Excel.

Note: In this tutorial, I’m going to use the words ‘sheet’ and ‘worksheet’ interchangeably. But to tell you the difference, Sheets would include Worksheets as well as Chart Sheets, but since Chart Sheets are not that commonly used, whenever I use the word Sheet consider it as a Worksheet.

Delete Sheets Using Right-Click Options

The easiest way to delete a worksheet in Excel is by using this simple two-click mouse technique.

Suppose, you have a worksheet that has three sheets as shown below, and you want to delete Sheet1.

Sheets in a workbook in Excel

Below are the steps to do this:

  1. Right-click on the sheet that you want to deleteRight-click on the sheet you want to delete
  2. Click on the delete optionClick on the Delete option
  3. In the prompt that shows up, click on the Delete buttonClick on Delete in the message box

You can also use the above technique on sheets that are not even the active sheet. For example, if I’m currently on Sheet1 and I want to delete Shee3, then I can simply right-click on Sheet3 and delete it.

You can also use the same technique to delete multiple sheets at once.

For example, if I want to delete Sheet2 and Sheet3 in one go, I can hold the control key and click on Sheet2 and Sheet3 one by one (while still holding the control key).

By holding the control key, Excel would allow me to select multiple sheets at one go. Once I’m done selecting the desired sheets, I can leave the control key. now I can right-click on any of the selected sheets tabs, and click on delete.

Remember that you cannot delete all the worksheets in a workbook in Excel. there always needs to be at least one sheet in the workbook. if you try and delete all the worksheets (or the only active sheet), you’ll see a prompt that will tell you that you’re not allowed to do this

Keyboard Shortcuts to Delete the WorkSheets

There is not one but two-and-half keyboard shortcuts that you can use to delete worksheets in Excel.

I say two and a half because one of the shortcuts he uses the mouse as well as the keyboard (and is still a faster way to do it)

Hybrid Keyboard Shortcut to Delete Sheet

Right-Click + D

To delete the selected worksheet or worksheets, right-click and then press the D key on your keyboard.

Personally, I find this a lot faster than just using the mouse to delete a worksheet (as I covered in the above section)

Regular Keyboard Shortcut to Delete Sheet

ALT + H + D + S

If you would rather prefer to ditch the mouse and only use the keyboard, the above keyboard shortcut will delete the active sheet or the selected sheets.

You need to press these keys in succession (i.e., one after the other)

While it may look like a slightly longer keyboard shortcut, once you get used to it it’s just as fast as any other technique covered in this tutorial

Legacy Keyboard Shortcut to Delete Worksheets

Like everyone else, Excel also has a past, and it’s not that pretty. I’m talking about the pre-ribbon style era.

For compatibility reasons, Excel still allows some of those old keyboard shortcuts to work in the newer versions. and in many cases, those earlier shortcuts are shorter and better.

Luckily, there is a legacy keyboard shortcut that works to delete worksheets in Excel

ALT + E + L

Deleting the ActiveSheet Using VBA

When it comes to deleting one sheet, or a couple of worksheets, it’s better to use the above-mentioned methods.

While VBA can automate the process, it’s usefulness comes in when you have to repeat the task multiple times.

As you will see, with VBA you can do a lot more when it comes to deleting worksheets in Excel.

So I’ll take you to more advanced use cases, but before that let’s see how to simply delete the active worksheet using VBA.

Below is the VBA code that will delete the active sheet:

Sub DeleteSheet()
ActiveSheet.Delete
End Sub

If you’re using it in the immediate window, you can simply use the below line:

ActiveSheet.Delete

When you use the above code to delete the active sheet, Excel would show you a prompt where you would have to click the delete button to confirm the action.

Deleting the Sheet Without Showing the Confirmation Prompt

The confirmation prompt message box is a useful feature that makes sure that you have a chance to cancel the deletion of the sheet in case you have run the code accidentally/erroneously

But if you already know what you’re doing, getting this prompt can be quite irritating.

so here is the VBA code that would make sure that the sheets are deleted but you do not see any confirmation prompt message box.

Sub DeleteSheet()
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub

In the above code, I have set the Application.DisplayAlerts property to false, which means that Excel will not show you any display alerts while the code is running.

It’s also really important to make sure that you turn it back to true at the end of the code to restore the functionality (as you can see I have done in the above code).

Caution: When you set the Application.DisplayAlerts property to false, Excel would simply delete the worksheet and there would be no way to recover it. so I advise you make a backup copy before you use this kind of code.

Deleting Sheet By Name (If It Exists) Using VBA

VBA allows you to automate the process of deleting a specific worksheet (on multiple worksheets) based on the sheet name.

For example, if you have a worksheet with the name ‘Sales’, you can use the below code to delete it:

Sub DeleteSheetByName()
Sheets("Sales").Delete
End Sub

This code would only delete the sheet that has the name Sales.

It’s useful when you have a workbook with a lot of sheets and you don’t want to sift through all the worksheets find the one with the name sales and delete it manually.

With the above code, it does not matter how many worksheets there are in the workbook it would simply delete the sales worksheet.

And since I have not changed the Application.DisplayAlert property, you will see a prompt where you would have to click the delete button to confirm the duration of the sales sheet.

In case you want to delete multiple sheets based on their name, you can do that as well.

For example, the below code would delete the sheets with the name Sales, Marketing, Finance:

Sub DeleteSheetsByName()
Sheets("Sales").Delete
Sheets("Marketing").Delete
Sheets("Finance").Delete
End Sub

Deleting All Sheets Except the Active Sheet Using VBA

If you have a workbook with multiple worksheets in it, and you want to delete all the worksheets except the active sheet, VBA is probably one of the better methods to do this.

Below is the VBA code that would delete all the sheets except the active sheet in the workbook.

Sub DeleteSheetByName()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Sheets
If ws.Name <> ActiveSheet.Name Then
ws.Delete
End If
Next ws
Application.DisplayAlerts = True
End Sub

Note that I have said the Application.DisplayAlerts property to falls at the beginning of the code, as I don’t want to see a prompt for every sheet that is deleted.

Delete All Sheets with a Specific Text String in the Name

This is a slightly more advanced use case of using VBA effectively when deleting worksheets.

Suppose you have a workbook with many different worksheets and you want to delete all the worksheets that have a specific text string in them then you can easily do that using VBA.

For example, below I have a workbook where I want to delete all the worksheets that have the text string “Sales” in them.

Below is the VBA code that would do that:

Sub DeleteSheetByName()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Sheets
If ws.Name Like "*" & "Sales" & "*" Then
MsgBox ws.Name
ws.Delete
End If
Next ws
Application.DisplayAlerts = True
End Sub

The above code uses the if-then statement to go through all the worksheets in the workbook. It checks the name of all these worksheets and if the name contains the word “Sales”, then that worksheet is deleted.

If you want to change the code and look for any other text string, you can change that in the fifth line of the above code.

Also note that I’ve used an asterisk (*), which is a wild card character, on both sides of the text string that we are looking for in the worksheet name. This ensures that no matter where the string appears in the name of the worksheet, it would still be deleted.

You can also modify the code to make sure that only those worksheets are deleted where the text string appears at the beginning of the worksheet name.

For example, if you want to delete those sheets where the term sales appear at the beginning, use the following code in the fifth line.

If ws.Name Like "*" & "Sales" & "*" Then

Here, I’ve used the wild card character only after the text drink and not before it. This will make sure at while checking the names of the worksheet, only those would satisfy the criteria where the term ‘Sales’ is at the beginning of the name.

So these are some of the methods that you can use when you want to delete sheets in Excel. In most cases, you can easily do this right within the worksheet by using the mouse or the keyboard shortcut.

But in case you have a heavy workbook with a lot of worksheets and you want to quickly delete specific kinds of sheets then you can also use VBA.

I hope you found this tutorial useful.

Other Excel tutorials you may also like:

  • How to Delete All Hidden Rows and Columns in Excel
  • How to Insert / Delete Comments in Excel (including Shortcuts)
  • How to Delete Entire Row in Excel Using VBA
  • How to Delete Every Other Row in Excel (or Every Nth Row)
  • Delete Blank Rows in Excel (with and without VBA)
  • How to Insert New Worksheet in Excel (Easy Shortcuts)
  • Excel Tabs/Sheets Not Showing – How to Fix?

To be specific, I want to delete all sheets except Sheet6 which is the code name of a sheet, but I can’t seem to make my code work.

  Dim ws As Worksheet

  For Each ws In ThisWorkbook.Worksheets
  If ws <> ThisWorkbook.Sheet6 Then

      Application.DisplayAlerts = False
      ws.Delete
      Application.DisplayAlerts = True

  End If

  Next ws

asked Jul 14, 2018 at 9:36

Sebastian Ong's user avatar

try

Dim ws As Worksheet

Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets
    If ws.CodeName <> "Sheet6" Then ws.Delete
Next
Application.DisplayAlerts = True

answered Jul 14, 2018 at 9:41

DisplayName's user avatar

DisplayNameDisplayName

13.2k2 gold badges11 silver badges19 bronze badges

1

Here’s an alternate with no vars.

application.displayalerts = false

with ThisWorkbook
    if .worksheets("sheet6").index > 1 then _
        .worksheets("sheet6").move before:=.sheets(1)
    do while .sheets.count > 1
        .sheets(2).delete
    loop
end with

application.displayalerts = true

answered Jul 14, 2018 at 12:38

When deleting, always iterate backwards (although Jeeped’s answer has a different way of addressing this).

    Dim iterator as long
    Application.DisplayAlerts = False
    For iterator = ThisWorkbook.Worksheets.Count To 1 Step -1
        With ThisWorkbook.Worksheets(iterator)
            if .CodeName <> "Sheet6" Then .Delete
        End With
    Next iterator
    Application.DisplayAlerts = True

answered Jul 14, 2018 at 21:28

AJD's user avatar

AJDAJD

2,3702 gold badges12 silver badges22 bronze badges

Excel workbooks can contain a large number of different worksheets. Combining all your worksheets in one workbook makes it easy to navigate between them, making data referencing easy and fast. Despite this, certain times while working with Excel worksheets, it reaches a time when you no longer need the data in individual worksheets. The only option remaining is to delete these sheets. Doing this helps in reducing your file size, and you can keep only data that is relevant.

So, to find out how you can delete your irrelevant sheets in excel, read below.

How to delete an Excel worksheet by Right-clicking

1. From the start button on your PC, access Microsoft Office Suite and click on the Microsoft Excel program.

2. Open the workbook file that contains sheets to delete.

3. At the bottom of the workbook, select the worksheet that you want to delete.

4. Right-click on the sheet name and a drop-down menu will be displayed.

5. Select the Delete option. A warning dialogue box pops up asking whether you want to continue the deleting process. Click the Delete tab. After deleting, your sheet will be removed permanently from your workbook.

Using the keyboard shortcut to delete a worksheet

1. From the start button on your keyboard’s PC, access Microsoft Office Suite and click on the Microsoft Excel program.

2. From the File tab, click on the Open option. It will direct you to your documents folder on your PC. From here, select the Excel file that contains the sheet you want to delete.

3. At the bottom of the workbook, select the worksheet that you want to delete.

4. On your keyboard, press the Alt+H+D+S keys. You can also press the Alt+E on your keyboard, then press L. After this, hit Enter. Your sheet will be removed from the workbook. Or you can decide to click on the delete dialogue box that would appear on your screen.

Deleting by Format option

1. At the bottom of your opened workbook, select the worksheet you want to delete.

2. From the main menu’s ribbon, go to the Home tab.

3. Under the group name ‘Cells’ found at the top of the window, select the Delete drop-down arrow. From the given menu list, click Delete Sheet.

4. After you have selected the Delete Sheet Option, you will get a warning dialogue box asking whether you want your sheet deleted permanently. Click on the Delete button.

5. When you go back to your workbook, the deleted sheet will not be available.

Note that;

You can also delete multiple worksheets from a workbook. Below are the steps you have to follow;

  • Select the sheets you want to delete. Do this by using the Shift and Ctrl keys.
  • Right-click, and from the drop-down menu, select Delete. Apart from this method, you can follow the above steps, and still, you will manage to delete all the selected sheets.

Conclusion

We have given you different ways of deleting Microsoft Excel worksheets from a workbook from the guide above. As long as you are a consistent user of excel or even a new user, deleting a sheet will not be a daunting problem while using the above steps. I hope the article is informative and useful.

Delete All Sheets Except One — Excel

How can I delete all worksheets in a workbook except for one with a given name? The titles of the other worksheets will vary, so I’m not sure how to do it (I only know how to delete based on a name; in this case, I want to always delete all worksheets except for «Main»).

Thanks in advance!

—Brendan—

Excel VBA Course

Excel VBA Course — From Beginner to Expert

200+ Video Lessons
50+ Hours of Instruction
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

(80% Discount Ends Soon!)

View Course


Similar Topics



Hi,
I need the necessity do delete a sequence of sheets in my workbook.
If I use this code:

With ActiveWorkbook
If .Worksheets.Count >= 5 Then
For n = 5 To .Worksheets.Count
Worksheets(n).Delete
Next n
End If
End With

I receive a confirmation message box with this message:

«Data may exist in the sheet(s) selected for deletion. To permanently delete the data, press Delete» [DELETE] [CANCEL]

I wish to delete all sheets without receiving any message.

Is it possible?

Many thanks in advance for your kind support.

Regards,

Giovanni

View Answers


Still learning VBA — I am trying to delete an entire row based on a condition in one cell in the row. Typically I would just filter on that value and delete the rows, but I am not sure if that is a possibility in VBA code. Can you provide the code if not too complex.

Select Cell A1 if value is 100 delete entire row, else skip to next row. Then loop through each row in the spreadsheet till all rows with selected cell equal to 100 are deleted.

View Answers


Hi All,

I have the below code which deletes all items from a listbox and my excel sheet which is the source for populating that listbox. I am using a option button style for my listbox and the selection style as single .i.e. you can select only one item at one go in the lisbox. I want my macro to delete the selected item from my worksheet .i.e. it’s entire row so that it doesn’t reflect in my lisbox any more. Below is my code :

Code:

Private Sub CommandButton2_Click()
 'REMOVE SELECTION
 
  Dim I As Long
 
    With ListBox1
      For I = .ListCount - 1 To 0 Step -1
       If .Selected(I) Then
           .RemoveItem I
           Sheets("URL List").Rows(I + 2).EntireRow.Delete
           
        End If
      Next I
    
End With

End Sub

Thanks a lot for your help in advance.

View Answers


How to create a userform that will have button for search, edit, change, delete individual recordings. Also in case of listed results obtained records that could be printed?

Thanks

View Answers


Hi,
how do I select (in VBA) all the rows that were filtered out by autofilter (using VBA code) and delete them leaving just header. I just can’t figure out how to select entire rows when the data is filtered…
Thanks for your hints!

View Answers


When I auto filter a spreadsheet, I can’t figure out how to delete or
eliminate from the sheet the filtered-out rows. So when I refilter the sheet
with new items to get rid of, the old filtered items come back. I’ve tried
copying the range to another file, but I always get all the old data in the
new file.

View Answers


I have a large spreadsheet in Excel 2007. I am converting it to a .csv file to import in to another program. I need to delete all commas from all data.

When I try to replace all commas (with nothing or with another character), I get the error message «The formula you typed contains an error.»

I have tried various formats (text, general, etc.) and various file types (.xls,.xlsx, .csv) and still get the same error.

View Answers


Hi all! Can anyone tell me the shortcut for Delete, Shift cells up? I have checked through Google but could not find the shortcut.

Thanks!

View Answers


Hi all.

I have set up a workbook that is sent out to lots of different users. They each keep and use their own copy.

I have set it up so that everything looks OK and is visible on MY screen, but I’m conscious that some users may have different screen sizes, different toolbars set up, and so on, which might make some parts not immediately visible to them.

I have set up an auto-execute macro which automatically sets the zoom factor to best fit, for several of the worksheets, and this works fine.
Here’s the code that does it.

Code:

Sheets("WELCOME").Select
    Range("A1:N18").Select
    ActiveWindow.Zoom = True

By repeating this code for each worksheet, I can make each one be zoomed just right.

However, the file contains 8 sheets that are all identically laid out, except the number of rows is different.
What I want to do is go to the worksheet that has the largest number of rows (it’s always the same worksheet, so I know which one it is), set the zoom factor for THAT worksheet (which I can do, and it always has the same number of rows), and then take THAT zoom factor, whatever it is — and it will vary depending on the user — and apply that to the other worksheets that have a similar layout.

I could just go through each worksheet and zoom it automatically, but that would mean that some of the sheets looked very large, others very small, and I’d like them to have a consistent appearance.
I could also specify a range on each worksheet that was similar to the appropriate range on the longest worksheet, and zoom that automatically, but that’s not ideal either, because some of the row heights vary from sheet to sheet, and again I’ll end up with different font sizes.

Anyone know how to do this ?

View Answers


We have a workbook that does not allow us to use the Move or Copy command. When we right click on the worksheet and select Move or Copy, we are able to check the box to make a copy, but when we click OK nothing happens.

We have checked to make sure that the workbook and worksheet:
1. Are not protected
2. That there are no hidden worksheets
3. That there are not worksheets that exist with the same name
4. That not all the worksheets are selected

There are only two worksheets in this workbook.

Any ideas of why we are unable to make a copy of this worksheet within the same workbook or to another workbook?

View Answers


Hi,

I’d like help in creating a macro that deletes an entire row that has emtpy cells in col B, C & D in the same row.
So for example if I have empty cells in b3,c3 & d3 I’d like the row deleted.

I’ve used the code below for just column B but I need to include column C & D as well. I tried putting Columns(«B:D») but it deletes everything.

Code:

Sub Step4()
   On Error Resume Next
   Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

I’m sure it’s something simple… like me !

Any help much appreciated

Wrightie

View Answers


I have protected a worksheet as it has several formulae on that I do not wat anyone else to mistakingly delete. I then have spent time on setting up a sheet to track changes (just in case this has any bearing on the problem). This is the only thing that I think I have changed since protecting this morning and now I cannot unprotect the sheet. I have not protected the workbook and the unprotect sheet function is now greyed out.

Any ideas?

View Answers


I have never really used VBA and so am completely stuck at this problem. I need to create a macro which auto-populates a master worksheet from the individual user sheets in a shared workbook.

Sheet 1 is the master sheet «Team Stats». There will be an undetermined number of individual worksheets to accomodate new staff.

Each worksheet will be identical, using columns A-I with row 1 having the headings:

Date, Name, Reference, Value, Price, Age, Purchased?, Destination, Add. Products (the last 3 columns will have a drop-down list which will be used to enter data into the cell).

There will be a varying number of rows in each of the individual sheets.

If possible I would like the macro to run every time data is entered into one of the individual worksheets. If this is not then it would be fien to update every time the workbook is opened.

If anyone can help it would really cut down the time I spend collating these stats every day!

View Answers


Hi there, longtime user firsttime poster. Looking for some help as I am a non-expert with macros. Here’s what I’m trying to do:

We have to submit things to a certain regulatory body and we usually enter tasks in as soon as they come, do the submission, and then keep a record of that submission.

So, I have a workbook with two sheets, one is «TO DO», the other is «ARCHIVE». Both sheets have the same columns and everything. I am looking for a macro that will automatically cut a (row) from the TO DO sheet and paste it in into the ARCHIVE sheet once it is done, then delete the cut row from the TO DO list so it stays topped up.

The trigger for archiving is the columns M and N which are titled «Complete ?» and each has a validation drop down that says «YES». When both cells in columns M and N have the YES in them, I would like the macro to make the above mentioned actions.

I ran a search on the forums and found something similar, but not quite what I was looking for.

Any help?

View Answers


Hi All,

Random question i have a large Excel Workbook (which is protected) and has over five sheets on it — however one sheet has randomly decided not to scroll… yes i know sounds random! If i use the cursor and down arrows the selection just disappears off the screen.
The page will scroll if i filter by one field, but not if i select (All) for all filters.
All other worksheets scroll fine.
Any suggestions?

Thanks in advance.
Cheers Kaite

View Answers


Is it possible to set multiple validation for a single cell in excel? Its
pretty straight forward to set a single validation so that a message is
displayed when incorrect data is entered. However, adding another validation
seems to delete the old one. Thanks in advance.

View Answers


I have an Excel workbook that was created by a former coworker. It includes a macro that, among other things, displays a message box about the 2008 file. The macro runs as soon as the file is opened. I’d like to access that macro to correct the date to 2011 and see what else, if anything, it’s doing for me (it doesn’t appear to do much). I can find references to creating macros to hide and unhide rows/columns and I found ways to delete all macros in a workbook, but I cannot find anything about unhiding a macro without knowing its name.

Does anyone know of a way to unhide this macro?

Thanks!

View Answers


Is it possible to import a single text file into Excel, splitting the incoming data across multiple worksheets rather than a single worksheet? Each each row on the text file would be evaluated by the value in one of it’s «columns» and written to the appropriate worksheet. The file is «!» delimited and has 11 columns for each row.

Currently, I import the file into one worksheet and cut/paste the rows manually into new worksheets/tabs. The files are very large, sometimes exceeding the 65,536 row limit, which I could avoid if the data was split out coming in.

Any help anyone could provide would be WONDERFUL. Thanks!

View Answers


Hi peeps

I want to combine data from several worksheets into one worksheet.

For example, I have data in Sheet1 (Columns A,B,C), data in Sheet2 (Columns A,B,C), data in Sheet3 (Columns A,B,C) all with varying amounts of rows. (All the rows contain text data).

I need to combine all of the data from the 3 sheets into a single sheet, Sheet4 (Columns A,B,C), eliminating the empty rows.

I’ve been looking into this for a while, and can’t find anything that really helps. Anyone got any pointers of what to look into?

Any help will be beautiful.

Cheers

View Answers


I have a requirement to change the panes in excel.
My excel file will contain more than one tab.
I have to free the first two lines in all the tabs except the first one.
I tried the following code.

Code:

xlsobj.Worksheets(1).Rows("1:2").Select
ActiveWindow.FreezePanes = True

But in this I have to change the Active Worksheets in VBA, Which I want to avoid.
Is there any method to achieve this without selecting the cells.
Something like

Code:

xlsobj.Worksheets(1).Rows("1:2").FreezePanes = True

View Answers


Понравилась статья? Поделить с друзьями:
  • Excel delete all blank rows
  • Excel could not load some objects because they are not available on this machine
  • Excel del запятая вместо точки
  • Excel cos в степени
  • Excel decode utf 8