Delete sheets depends on condition

4 views
Skip to first unread message

Gaytri Thakur

unread,
Sep 14, 2011, 7:45:32 AM9/14/11
to exce...@googlegroups.com
Hello All,
Can any one suggest me,actually i am facing two problem.

1.I am getting error,When i am creating new sheet and trying to name it "Inventory". It is showing following error.

"Cannot rename a sheet to the same name as another sheet, a
referenced object library or a workbook referenced by visual basic"


2.Using Vba i am getting data from net to different different sheets.
   Now i want to delete all sheet but not master, main and inventory.



Please suggest....

Robert James

unread,
Sep 15, 2011, 12:54:53 AM9/15/11
to exce...@googlegroups.com
Hello Gaytri,
If this workbook is send by another user,Make sure that Inventory sheet is hide or strictly hide.
I guess that you got a workbook where Inventory sheet Marked Hidden.Please let me know after Verification.


Your second answer,Off course you can delete many unnecessary sheets while keeping some in your Workbook.
Try this code.

Sub DelAllNotMain()
Dim Wrksht As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each Wrksht In Worksheets
If Wrksht.Name <> "Master" And Wrksht.Name <> "Main" And Wrksht.Name <> "Inventory" Then Wrksht.Delete
Next
Application.ScreenUpdating = True
End Sub




--
You received this message because you are subscribed to the Google Groups "MS Excel Macro Vba" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to excel_vba+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/excel_vba?hl=en.

Gaytri Thakur

unread,
Sep 15, 2011, 5:52:35 AM9/15/11
to exce...@googlegroups.com
Hello James,
This macro is working fine.Thanks for your time.Actually i got this workbook from other team,
and the sheet Inventory was marked Hide.

Rest is fine.Thanks for your time and kind assistance.


Please favor me, Can we save all worksheet as a workbook.
Suppose i have sheet1 to sheet1000, manually i have to copy paste in new workbook,
to separate the data.
Reply all
Reply to author
Forward
0 new messages