Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Why does this code not work across all designated sheets now ?

The below code suppose to clear the values in the Range to = ""
But for some reason it works if i run the macro from an activeworksheet,
but it does NOT Clear the values in ALL shets(Minus the named 3 sheets).

I also had to add the (On error resume next) as i was getting a Cannot change part of a Merged Cell
error,
But with those ranges there Are NO Merged Cells????

Sub ClearTimeSheetValues()
Call Unprotect
On Error Resume Next
Dim myrange As Range
For Each sh In ThisWorkbook.Worksheets
If sh.Name < "Enter - Exit" And sh.Name < "Utilization Sheet" And sh.Name < "Leave Blank" Then
Set myrange = Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R16,U 5:U15")
With myrange
..Value = ""
Range("A1").Select
End With
End If
Next
Call protect
End Sub

Any ideas' to get this code working again ?

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Why does this code not work across all designated sheets now ?

Corey,

Some of your range references are referring to the active worksheet (over
and over). You need to qualify the ranges you are referring to, for
example:

Set myrange = ws.Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R1 6,U5:U15")
and
ws.Range("A1").Select

I suspect that if you look at the active worksheet you'll find a merged cell
in one of the ranges referred to in your code, which would explain that
problem.

hth,

Doug

"Corey" wrote in message
...
The below code suppose to clear the values in the Range to = ""
But for some reason it works if i run the macro from an activeworksheet,
but it does NOT Clear the values in ALL shets(Minus the named 3 sheets).

I also had to add the (On error resume next) as i was getting a Cannot
change part of a Merged Cell
error,
But with those ranges there Are NO Merged Cells????

Sub ClearTimeSheetValues()
Call Unprotect
On Error Resume Next
Dim myrange As Range
For Each sh In ThisWorkbook.Worksheets
If sh.Name < "Enter - Exit" And sh.Name < "Utilization Sheet" And
sh.Name < "Leave Blank" Then
Set myrange = Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R16,U 5:U15")
With myrange
.Value = ""
Range("A1").Select
End With
End If
Next
Call protect
End Sub

Any ideas' to get this code working again ?

Corey....




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Why does this code not work across all designated sheets now ?

Unqualified objects (normally) refer to the Activesheet. hence:
Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R16,U 5:U15")
is always the same sheet. You need to include the reference to which sheet
the range is on. i.e.
sh.Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R1 6,U5:U15")

Also, what do you intend with this ?
Range("A1").Select

Do you mean ?
sh.Range("A1").Select

If so you will need to activate the sheet first, as you cannot .select on a
non-active sheet.

NickHK

"Corey" wrote in message
...
The below code suppose to clear the values in the Range to = ""
But for some reason it works if i run the macro from an activeworksheet,
but it does NOT Clear the values in ALL shets(Minus the named 3 sheets).

I also had to add the (On error resume next) as i was getting a Cannot

change part of a Merged Cell
error,
But with those ranges there Are NO Merged Cells????

Sub ClearTimeSheetValues()
Call Unprotect
On Error Resume Next
Dim myrange As Range
For Each sh In ThisWorkbook.Worksheets
If sh.Name < "Enter - Exit" And sh.Name < "Utilization Sheet" And

sh.Name < "Leave Blank" Then
Set myrange = Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R16,U 5:U15")
With myrange
.Value = ""
Range("A1").Select
End With
End If
Next
Call protect
End Sub

Any ideas' to get this code working again ?

Corey....




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Why does this code not work across all designated sheets now ?

Thanks Nick.

I have a litle better understanding of why it was not working now.
All is good.

Cheers

"NickHK" wrote in message ...
Unqualified objects (normally) refer to the Activesheet. hence:
Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R16,U 5:U15")
is always the same sheet. You need to include the reference to which sheet
the range is on. i.e.
sh.Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R1 6,U5:U15")

Also, what do you intend with this ?
Range("A1").Select

Do you mean ?
sh.Range("A1").Select

If so you will need to activate the sheet first, as you cannot .select on a
non-active sheet.

NickHK

"Corey" wrote in message
...
The below code suppose to clear the values in the Range to = ""
But for some reason it works if i run the macro from an activeworksheet,
but it does NOT Clear the values in ALL shets(Minus the named 3 sheets).

I also had to add the (On error resume next) as i was getting a Cannot

change part of a Merged Cell
error,
But with those ranges there Are NO Merged Cells????

Sub ClearTimeSheetValues()
Call Unprotect
On Error Resume Next
Dim myrange As Range
For Each sh In ThisWorkbook.Worksheets
If sh.Name < "Enter - Exit" And sh.Name < "Utilization Sheet" And

sh.Name < "Leave Blank" Then
Set myrange = Range("C5:C16,F5:F16,I5:I16,L5:L16,O5:O16,R5:R16,U 5:U15")
With myrange
.Value = ""
Range("A1").Select
End With
End If
Next
Call protect
End Sub

Any ideas' to get this code working again ?

Corey....





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 repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Programming 6 March 29th 06 12:43 PM
Code to protect sheets, protects work book also? thiaga Excel Programming 7 March 2nd 06 11:00 PM
change code to work over multiple sheets cda_cmd Excel Programming 2 February 15th 06 01:05 AM
Counting dates in multiple work sheets and work books Savage Excel Discussion (Misc queries) 0 December 19th 05 11:41 PM
I wish to save my Excell work in my work sheets CLC 37 Qld Excel Worksheet Functions 0 May 24th 05 10:56 AM


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