PC Review


Reply
Thread Tools Rate Thread

Code not doing what I hoped for

 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      5th Dec 2008
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 With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      5th Dec 2008
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 With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      5th Dec 2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
Patrick C. Simonds
Guest
Posts: n/a
 
      6th Dec 2008
Thanks

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


"Mike H" <(E-Mail Removed)> wrote in message
news:757B60F1-55D1-4EE8-A84F-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
RANK not resulting as hoped Jeff Microsoft Excel Misc 8 24th Apr 2008 11:32 PM
Not getting hoped for result Patrick C. Simonds Microsoft Excel Programming 3 7th Apr 2008 12:09 AM
2007 - two features not there that I'd hoped for DianaH Microsoft Powerpoint 9 5th Jul 2006 01:44 PM
Textbox displays more than I hoped for... pauldr Microsoft Dot NET Framework Forms 5 19th Jan 2006 10:47 PM
[New] Zipoid - ZIP Code, City Name and Area Code Lookup - Zip Code to Zip Code Distance Calculation Mel Freeware 0 22nd Jul 2005 04:13 PM


Features
 

Advertising
 

Newsgroups
 


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