Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Worksheet_Deactivate() problem with deleting data


Hi I need to delete formaulas when a sheet deactivates but the formulas in
the next sheet thats acivated are deleted instead, is there a way to do
this? (the formaulas are copied in when the worksheets are activated)

Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect Password:="naWages"
Range("AG17:AH41").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("AY17:CI42").Select
Selection.ClearContents
Range("A1").Select
ActiveSheet.Protect Password:="naWages"
End Sub

Regards
Neil



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Worksheet_Deactivate() problem with deleting data

Hi Neil,

The following adaptation worked for me:

'====================
Private Sub Worksheet_Deactivate()

On Error GoTo XIT

Application.EnableEvents = False

With Me

.Unprotect Password:="naWages"

With .Range("AG17:AH41")
.Value = .Value
End With

.Range("AY17:CI42").ClearContents
.Protect Password:="naWages"

End With

XIT:
Application.EnableEvents = True

End Sub
'<<====================

BTW. apart from the fact that selections are rarely necessary, or desirable,
I would have expected your code to fail on the line:

Range("AG17:AH41").Select


given that a selection cannot be made on an inactive sheet.


---
Regards,
Norman



"Karoo News" wrote in message
...

Hi I need to delete formaulas when a sheet deactivates but the formulas in
the next sheet thats acivated are deleted instead, is there a way to do
this? (the formaulas are copied in when the worksheets are activated)

Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect Password:="naWages"
Range("AG17:AH41").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("AY17:CI42").Select
Selection.ClearContents
Range("A1").Select
ActiveSheet.Protect Password:="naWages"
End Sub

Regards
Neil




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Worksheet_Deactivate() problem with deleting data

That worked fantastic - many thanks - Neil

"Norman Jones" wrote in message
...
Hi Neil,

The following adaptation worked for me:

'====================
Private Sub Worksheet_Deactivate()

On Error GoTo XIT

Application.EnableEvents = False

With Me

.Unprotect Password:="naWages"

With .Range("AG17:AH41")
.Value = .Value
End With

.Range("AY17:CI42").ClearContents
.Protect Password:="naWages"

End With

XIT:
Application.EnableEvents = True

End Sub
'<<====================

BTW. apart from the fact that selections are rarely necessary, or
desirable, I would have expected your code to fail on the line:

Range("AG17:AH41").Select


given that a selection cannot be made on an inactive sheet.


---
Regards,
Norman



"Karoo News" wrote in message
...

Hi I need to delete formaulas when a sheet deactivates but the formulas
in the next sheet thats acivated are deleted instead, is there a way to
do this? (the formaulas are copied in when the worksheets are activated)

Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect Password:="naWages"
Range("AG17:AH41").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("AY17:CI42").Select
Selection.ClearContents
Range("A1").Select
ActiveSheet.Protect Password:="naWages"
End Sub

Regards
Neil






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Worksheet_Deactivate() problem with deleting data

why not use the workbook level sheetdeactivate event. then you have a
reference to the sheet being deactivated. Remove all the selecting - since
the sheet is not the active sheet. write references to your locations

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
if sh.Name = "MySheet" then
with sh
.Unprotect Password:="naWages"
. Range("AG17:AH41").Formula = _
.Range("AG17:AH41:).Value
.Range("AY17:CI42").ClearContents
.Protect Password:="naWages"
End With
End if
End Sub

--
Regards,
Tom Ogilvy

"Karoo News" wrote in message
...

Hi I need to delete formaulas when a sheet deactivates but the formulas in
the next sheet thats acivated are deleted instead, is there a way to do
this? (the formaulas are copied in when the worksheets are activated)

Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect Password:="naWages"
Range("AG17:AH41").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("AY17:CI42").Select
Selection.ClearContents
Range("A1").Select
ActiveSheet.Protect Password:="naWages"
End Sub

Regards
Neil





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
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
Capturing the selected tab in a worksheet_deactivate macro jkitzy Excel Programming 1 December 24th 04 09:01 PM
Excel – Macro Problem – Inserting, Appending Data, Deleting Aussiexcel[_3_] Excel Programming 0 August 25th 04 07:48 AM
Deleting Web Query Problem dule[_6_] Excel Programming 1 February 27th 04 07:17 PM
Row deleting script problem jessica Excel Programming 1 October 15th 03 11:55 AM


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