Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default 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!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default 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!






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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!








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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!

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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!

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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!



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find and unlink current worksheet from old worksheet kmjmail Excel Discussion (Misc queries) 3 January 12th 09 10:52 PM
Find worksheet LantzK Excel Discussion (Misc queries) 1 May 23rd 08 05:19 PM
Can't find worksheet? davegb Excel Programming 2 May 12th 05 07:03 PM
Find worksheet cottage6 Excel Programming 8 April 21st 05 05:43 PM
find last row in another worksheet gaba Excel Programming 2 April 12th 05 04:24 AM


All times are GMT +1. The time now is 01:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"