Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Code not doing what I hoped for

Can anyone tell me why the code below only works on the worksheet that's
active when it is run? My hope was that it would go to each worksheet
(excluding Holidays) and remove all shapes and clear the value in cell F1

Sub HolidayRemove()

Protection.UnProtectAllSheets

For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
With Sheets(n)

ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""

End With
End If

Next n

Protection.ProtectAllSheets
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Code not doing what I hoped for

Hi,

Try this but be aware

ActiveSheet.Shapes.SelectAll
Selection.Delete

is a very blunt instrument and may delete more than you bargained for. try
it on a test workbook.


Sub HolidayRemove()
For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
Sheets(n).Select
Sheets(n).Unprotect
With Sheets(n)
ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""
Sheets(n).Protect
End With
End If
Next n
End Sub


Mike

"Patrick C. Simonds" wrote:

Can anyone tell me why the code below only works on the worksheet that's
active when it is run? My hope was that it would go to each worksheet
(excluding Holidays) and remove all shapes and clear the value in cell F1

Sub HolidayRemove()

Protection.UnProtectAllSheets

For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
With Sheets(n)

ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""

End With
End If

Next n

Protection.ProtectAllSheets
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Code not doing what I hoped for

untested, but give it a try

Sub HolidayRemove()

Dim n As Long

For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
With Sheets(n)
.Activate
.Unprotect
.Shapes.SelectAll
Selection.Delete
.Range("K1").Value = ""
.Protect
End With
End If

Next n


End Sub


--


Gary

"Patrick C. Simonds" wrote in message
...
Can anyone tell me why the code below only works on the worksheet that's
active when it is run? My hope was that it would go to each worksheet
(excluding Holidays) and remove all shapes and clear the value in cell F1

Sub HolidayRemove()

Protection.UnProtectAllSheets

For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
With Sheets(n)

ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""

End With
End If

Next n

Protection.ProtectAllSheets
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Code not doing what I hoped for

Thanks

Any way that can be made to return me to the worksheet and cell were the
code was triggered?


"Mike H" wrote in message
...
Hi,

Try this but be aware

ActiveSheet.Shapes.SelectAll
Selection.Delete

is a very blunt instrument and may delete more than you bargained for. try
it on a test workbook.


Sub HolidayRemove()
For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
Sheets(n).Select
Sheets(n).Unprotect
With Sheets(n)
ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""
Sheets(n).Protect
End With
End If
Next n
End Sub


Mike

"Patrick C. Simonds" wrote:

Can anyone tell me why the code below only works on the worksheet that's
active when it is run? My hope was that it would go to each worksheet
(excluding Holidays) and remove all shapes and clear the value in cell F1

Sub HolidayRemove()

Protection.UnProtectAllSheets

For n = 1 To Sheets.Count
If Sheets(n).Name < "Holidays" Then
With Sheets(n)

ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""

End With
End If

Next n

Protection.ProtectAllSheets
End Sub



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
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Excel Programming 6 October 3rd 08 09:45 PM
RANK not resulting as hoped Jeff Excel Discussion (Misc queries) 8 April 24th 08 11:32 PM
Not getting hoped for result Patrick C. Simonds Excel Programming 3 April 7th 08 12:09 AM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM


All times are GMT +1. The time now is 05:31 PM.

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

About Us

"It's about Microsoft Excel"