![]() |
Find a Worksheet
Does anyone have a suggestion on how you could find a worksheet in a written
code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Application.DisplayAlerts = False
Worksheets("sheetname").Delete Application.DisplayAlerts = True -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Anice" wrote in message ... Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Try this
on error resume next application.displayalerts = false sheets("Sheet1").delete application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Not to pick Bob, but if the sheet does not exist then the code will crash
before the alerts get turned back on again and the application will continue to not display alerts until Excel if re-booted (I believe that this is one of those settings that automatically resets itself when re-booted). Some kind of error handling would be a good thing... -- HTH... Jim Thomlinson "Bob Phillips" wrote: Application.DisplayAlerts = False Worksheets("sheetname").Delete Application.DisplayAlerts = True -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Anice" wrote in message ... Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Thank you very much. Now lets say you want to delete all the sheets after
this first sheet. It could be anywhere from 2 sheets to 10 sheets. "Jim Thomlinson" wrote: Try this on error resume next application.displayalerts = false sheets("Sheet1").delete application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Agreed Jim, but the way that I read the request, he seemed to know the sheet
exists. -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Jim Thomlinson" wrote in message ... Not to pick Bob, but if the sheet does not exist then the code will crash before the alerts get turned back on again and the application will continue to not display alerts until Excel if re-booted (I believe that this is one of those settings that automatically resets itself when re-booted). Some kind of error handling would be a good thing... -- HTH... Jim Thomlinson "Bob Phillips" wrote: Application.DisplayAlerts = False Worksheets("sheetname").Delete Application.DisplayAlerts = True -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Anice" wrote in message ... Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
I am not too sure how you define "the first sheet" so you can modify this as
you see fit dim wks as worksheet on error resume next application.displayalerts = false for each wks in worksheets if wks.name < "The sheet I am keeping name" then wks.delete next wks application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Thank you very much. Now lets say you want to delete all the sheets after this first sheet. It could be anywhere from 2 sheets to 10 sheets. "Jim Thomlinson" wrote: Try this on error resume next application.displayalerts = false sheets("Sheet1").delete application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Fair enough. I am in the middle of debugging someone elses code that was
toggling application settings it has messed up some computers. I am a little sensitive / frustrated at the moment. But ain't that always the way... -- HTH... Jim Thomlinson "Bob Phillips" wrote: Agreed Jim, but the way that I read the request, he seemed to know the sheet exists. -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Jim Thomlinson" wrote in message ... Not to pick Bob, but if the sheet does not exist then the code will crash before the alerts get turned back on again and the application will continue to not display alerts until Excel if re-booted (I believe that this is one of those settings that automatically resets itself when re-booted). Some kind of error handling would be a good thing... -- HTH... Jim Thomlinson "Bob Phillips" wrote: Application.DisplayAlerts = False Worksheets("sheetname").Delete Application.DisplayAlerts = True -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Anice" wrote in message ... Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
If you realy mean the first sheet you could also do like this:
Sub DeleteSheet() Dim i As Integer Application.DisplayAlerts = False For i = Sheets.Count To 2 Step -1 Sheets(i).Delete Next i Application.DisplayAlerts = True End Sub "Jim Thomlinson" wrote in message ... I am not too sure how you define "the first sheet" so you can modify this as you see fit dim wks as worksheet on error resume next application.displayalerts = false for each wks in worksheets if wks.name < "The sheet I am keeping name" then wks.delete next wks application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Thank you very much. Now lets say you want to delete all the sheets after this first sheet. It could be anywhere from 2 sheets to 10 sheets. "Jim Thomlinson" wrote: Try this on error resume next application.displayalerts = false sheets("Sheet1").delete application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
Find a Worksheet
Thank you. Everyone has been very helpful. I know where I need to go with
it now. Thanks again! "Alf Bryn" wrote: If you realy mean the first sheet you could also do like this: Sub DeleteSheet() Dim i As Integer Application.DisplayAlerts = False For i = Sheets.Count To 2 Step -1 Sheets(i).Delete Next i Application.DisplayAlerts = True End Sub "Jim Thomlinson" wrote in message ... I am not too sure how you define "the first sheet" so you can modify this as you see fit dim wks as worksheet on error resume next application.displayalerts = false for each wks in worksheets if wks.name < "The sheet I am keeping name" then wks.delete next wks application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Thank you very much. Now lets say you want to delete all the sheets after this first sheet. It could be anywhere from 2 sheets to 10 sheets. "Jim Thomlinson" wrote: Try this on error resume next application.displayalerts = false sheets("Sheet1").delete application.displayalerts = true on error goto 0 -- HTH... Jim Thomlinson "Anice" wrote: Does anyone have a suggestion on how you could find a worksheet in a written code. You have the name, and you want the program to find that sheet and delete it. Thank you! |
All times are GMT +1. The time now is 11:41 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com