Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Looping through sheets

I'm trying to go throug all sheets in the active workbook and delete some of
them based on the sheet name. This is what i have so far:

Dim WSS As Worksheet
For Each WSS In ActiveWorkbook
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

I get an error about the "ActiveWorkbook" in line two.

Anyone able to help me out?
The Doctor
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Looping through sheets

Sub marine()
Dim WSS As Worksheet
For Each WSS In ActiveWorkbook.Sheets
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

End Sub


Note that the code does not die, but the message is issued whether the sheet
is deleted or not.
--
Gary''s Student - gsnu200908


"Dr. Schwartz" wrote:

I'm trying to go throug all sheets in the active workbook and delete some of
them based on the sheet name. This is what i have so far:

Dim WSS As Worksheet
For Each WSS In ActiveWorkbook
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

I get an error about the "ActiveWorkbook" in line two.

Anyone able to help me out?
The Doctor

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Looping through sheets

Thanks Gary!

Do you also know this then? When the sheet is deleted i'm prompted with a
message saying all data in the sheet will be lost. I know that it is possible
to bypass (not show) this message using code but i can not remember how...

Do you or anyone else know this?
Thanks / The Doctor

"Gary''s Student" wrote:

Sub marine()
Dim WSS As Worksheet
For Each WSS In ActiveWorkbook.Sheets
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

End Sub


Note that the code does not die, but the message is issued whether the sheet
is deleted or not.
--
Gary''s Student - gsnu200908


"Dr. Schwartz" wrote:

I'm trying to go throug all sheets in the active workbook and delete some of
them based on the sheet name. This is what i have so far:

Dim WSS As Worksheet
For Each WSS In ActiveWorkbook
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

I get an error about the "ActiveWorkbook" in line two.

Anyone able to help me out?
The Doctor

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Looping through sheets

Application.DisplayAlerts=False
--
Gary''s Student - gsnu200908


"Dr. Schwartz" wrote:

Thanks Gary!

Do you also know this then? When the sheet is deleted i'm prompted with a
message saying all data in the sheet will be lost. I know that it is possible
to bypass (not show) this message using code but i can not remember how...

Do you or anyone else know this?
Thanks / The Doctor

"Gary''s Student" wrote:

Sub marine()
Dim WSS As Worksheet
For Each WSS In ActiveWorkbook.Sheets
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

End Sub


Note that the code does not die, but the message is issued whether the sheet
is deleted or not.
--
Gary''s Student - gsnu200908


"Dr. Schwartz" wrote:

I'm trying to go throug all sheets in the active workbook and delete some of
them based on the sheet name. This is what i have so far:

Dim WSS As Worksheet
For Each WSS In ActiveWorkbook
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

I get an error about the "ActiveWorkbook" in line two.

Anyone able to help me out?
The Doctor

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Looping through sheets

Thats the one! Thanks :-)

"Gary''s Student" wrote:

Application.DisplayAlerts=False
--
Gary''s Student - gsnu200908


"Dr. Schwartz" wrote:

Thanks Gary!

Do you also know this then? When the sheet is deleted i'm prompted with a
message saying all data in the sheet will be lost. I know that it is possible
to bypass (not show) this message using code but i can not remember how...

Do you or anyone else know this?
Thanks / The Doctor

"Gary''s Student" wrote:

Sub marine()
Dim WSS As Worksheet
For Each WSS In ActiveWorkbook.Sheets
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

End Sub


Note that the code does not die, but the message is issued whether the sheet
is deleted or not.
--
Gary''s Student - gsnu200908


"Dr. Schwartz" wrote:

I'm trying to go throug all sheets in the active workbook and delete some of
them based on the sheet name. This is what i have so far:

Dim WSS As Worksheet
For Each WSS In ActiveWorkbook
MsgBox "now " & WSS.Name & " will be deleted"
If Right(WSS.Name, 2) = "_1" Then WSS.Delete
Next

I get an error about the "ActiveWorkbook" in line two.

Anyone able to help me out?
The Doctor

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
Looping through sheets ReportSmith Excel Programming 4 April 3rd 07 06:20 PM
Looping through Sheets Jim Thomlinson[_3_] Excel Programming 3 September 25th 04 03:48 AM
Looping through Sheets dalejrstwin Excel Programming 0 September 24th 04 06:43 PM
Looping through sheets Eric[_7_] Excel Programming 1 July 24th 03 04:45 PM


All times are GMT +1. The time now is 01:59 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"