Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default WorkSheet Event - Copied

xl2k on win2kPro.

I have a workbook that has a "Worksheet_SelectionChange" event on the initial sheet that
works just fine.

Once entry is complete the user runs a macro (located in a separate module) that copies
the sheet (creates another sheet in the same workbook via "OrdEnt.Copy After:=OrdEnt").

Works fine, except;
The worksheet change event can still be fired on the newly created (copied) sheet.
I suppose I could copy/paste the sheet to get rid of the change event but was wondering if
there's another way?

Hints?
--
Regards;
Rob
------------------------------------------------------------------------


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default WorkSheet Event - Copied

1) Instead of copying sheet you insert a new sheet and copy the used rage in
sheet OrdEnt to the new sheet.
e.g.:
Dim newSheet As Worksheet
Set newSheet = Worksheets.Add(After:=OrdEnt)
With Worksheets("OrdEnt").UsedRange
.Copy Destination:=newSheet.Cells(.Cells(1, 1).Row, .Cells(1,
1).Column)
End With

2) OR in the Worksheet_SelectionChange code of OrdEnt, Add following line
at the top:
If Not Me.Name = "OrdEnt" Then Exit Sub
So the code will be copied to new sheet, event will be fired but will exit
immediately with above
first line.

3) OR see below link - how to remove the code, through VBA
http://www.cpearson.com/excel/vbe.htm

Sharad


"RWN" wrote in message
...
xl2k on win2kPro.

I have a workbook that has a "Worksheet_SelectionChange" event on the
initial sheet that
works just fine.

Once entry is complete the user runs a macro (located in a separate
module) that copies
the sheet (creates another sheet in the same workbook via "OrdEnt.Copy
After:=OrdEnt").

Works fine, except;
The worksheet change event can still be fired on the newly created
(copied) sheet.
I suppose I could copy/paste the sheet to get rid of the change event but
was wondering if
there's another way?

Hints?
--
Regards;
Rob
------------------------------------------------------------------------




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default WorkSheet Event - Copied

Some good suggestions there.
Just to add...

UsedRange does not necessarily start on row/column 1.


You could move the Worksheet events into the Workbook.
That way the worksheet doesnt contain code.
eg.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
If Sh.CodeName = "OrdEnt" Then
Beep
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Sharad Naik" wrote in message
...
1) Instead of copying sheet you insert a new sheet and copy the used rage
in sheet OrdEnt to the new sheet.
e.g.:
Dim newSheet As Worksheet
Set newSheet = Worksheets.Add(After:=OrdEnt)
With Worksheets("OrdEnt").UsedRange
.Copy Destination:=newSheet.Cells(.Cells(1, 1).Row, .Cells(1,
1).Column)
End With

2) OR in the Worksheet_SelectionChange code of OrdEnt, Add following line
at the top:
If Not Me.Name = "OrdEnt" Then Exit Sub
So the code will be copied to new sheet, event will be fired but will exit
immediately with above
first line.

3) OR see below link - how to remove the code, through VBA
http://www.cpearson.com/excel/vbe.htm

Sharad


"RWN" wrote in message
...
xl2k on win2kPro.

I have a workbook that has a "Worksheet_SelectionChange" event on the
initial sheet that
works just fine.

Once entry is complete the user runs a macro (located in a separate
module) that copies
the sheet (creates another sheet in the same workbook via "OrdEnt.Copy
After:=OrdEnt").

Works fine, except;
The worksheet change event can still be fired on the newly created
(copied) sheet.
I suppose I could copy/paste the sheet to get rid of the change event but
was wondering if
there's another way?

Hints?
--
Regards;
Rob
------------------------------------------------------------------------






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default WorkSheet Event - Copied

Yes moving to Workbook class is good and simplest solution for him!
So RWN, if I were you I would go with Ron's suggestion.

BTW, just for informaion : - yes UsedRange does not necessarily start at
row/column 1,
But UsedRange.Cells(1, 1).Row returns the row where it starts (and
simillarly .Column returns the Column where it starts),
hence the code I gave, copies it on new sheet same place as it was on
original sheet.

Sharad

"Rob van Gelder" wrote in message
...
Some good suggestions there.
Just to add...

UsedRange does not necessarily start on row/column 1.


You could move the Worksheet events into the Workbook.
That way the worksheet doesnt contain code.
eg.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
If Sh.CodeName = "OrdEnt" Then
Beep
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Sharad Naik" wrote in message
...
1) Instead of copying sheet you insert a new sheet and copy the used rage
in sheet OrdEnt to the new sheet.
e.g.:
Dim newSheet As Worksheet
Set newSheet = Worksheets.Add(After:=OrdEnt)
With Worksheets("OrdEnt").UsedRange
.Copy Destination:=newSheet.Cells(.Cells(1, 1).Row, .Cells(1,
1).Column)
End With

2) OR in the Worksheet_SelectionChange code of OrdEnt, Add following
line at the top:
If Not Me.Name = "OrdEnt" Then Exit Sub
So the code will be copied to new sheet, event will be fired but will
exit immediately with above
first line.

3) OR see below link - how to remove the code, through VBA
http://www.cpearson.com/excel/vbe.htm

Sharad


"RWN" wrote in message
...
xl2k on win2kPro.

I have a workbook that has a "Worksheet_SelectionChange" event on the
initial sheet that
works just fine.

Once entry is complete the user runs a macro (located in a separate
module) that copies
the sheet (creates another sheet in the same workbook via "OrdEnt.Copy
After:=OrdEnt").

Works fine, except;
The worksheet change event can still be fired on the newly created
(copied) sheet.
I suppose I could copy/paste the sheet to get rid of the change event
but was wondering if
there's another way?

Hints?
--
Regards;
Rob
------------------------------------------------------------------------








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default WorkSheet Event - Copied

Sharad,

I missed the With. Your technique is correct - my apologies.

Rob


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Sharad Naik" wrote in message
...
Yes moving to Workbook class is good and simplest solution for him!
So RWN, if I were you I would go with Ron's suggestion.

BTW, just for informaion : - yes UsedRange does not necessarily start at
row/column 1,
But UsedRange.Cells(1, 1).Row returns the row where it starts (and
simillarly .Column returns the Column where it starts),
hence the code I gave, copies it on new sheet same place as it was on
original sheet.

Sharad

"Rob van Gelder" wrote in message
...
Some good suggestions there.
Just to add...

UsedRange does not necessarily start on row/column 1.


You could move the Worksheet events into the Workbook.
That way the worksheet doesnt contain code.
eg.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)
If Sh.CodeName = "OrdEnt" Then
Beep
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Sharad Naik" wrote in message
...
1) Instead of copying sheet you insert a new sheet and copy the used
rage in sheet OrdEnt to the new sheet.
e.g.:
Dim newSheet As Worksheet
Set newSheet = Worksheets.Add(After:=OrdEnt)
With Worksheets("OrdEnt").UsedRange
.Copy Destination:=newSheet.Cells(.Cells(1, 1).Row, .Cells(1,
1).Column)
End With

2) OR in the Worksheet_SelectionChange code of OrdEnt, Add following
line at the top:
If Not Me.Name = "OrdEnt" Then Exit Sub
So the code will be copied to new sheet, event will be fired but will
exit immediately with above
first line.

3) OR see below link - how to remove the code, through VBA
http://www.cpearson.com/excel/vbe.htm

Sharad


"RWN" wrote in message
...
xl2k on win2kPro.

I have a workbook that has a "Worksheet_SelectionChange" event on the
initial sheet that
works just fine.

Once entry is complete the user runs a macro (located in a separate
module) that copies
the sheet (creates another sheet in the same workbook via "OrdEnt.Copy
After:=OrdEnt").

Works fine, except;
The worksheet change event can still be fired on the newly created
(copied) sheet.
I suppose I could copy/paste the sheet to get rid of the change event
but was wondering if
there's another way?

Hints?
--
Regards;
Rob
------------------------------------------------------------------------












  #6   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default WorkSheet Event - Copied

Thanks to both Ron & Sharad.
(used the exit based on sheet name)
Also learned something, that's what I get for being "lazy" when I copy a sheet and then
add an event!

Again, thanks.

--
Regards;
Rob
------------------------------------------------------------------------
"RWN" wrote in message ...
xl2k on win2kPro.

I have a workbook that has a "Worksheet_SelectionChange" event on the initial sheet that
works just fine.

Once entry is complete the user runs a macro (located in a separate module) that copies
the sheet (creates another sheet in the same workbook via "OrdEnt.Copy After:=OrdEnt").

Works fine, except;
The worksheet change event can still be fired on the newly created (copied) sheet.
I suppose I could copy/paste the sheet to get rid of the change event but was wondering

if
there's another way?

Hints?
--
Regards;
Rob
------------------------------------------------------------------------




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 protect a worksheet from being copied to another worksheet SurvivorIT Excel Discussion (Misc queries) 3 August 31st 05 01:53 PM
Event Procedures: Event on Worksheet to fire Event on another Worksheet Kathryn Excel Programming 2 April 7th 04 07:35 PM
Copying Worksheet triggers Click event of combobox on another worksheet Robert[_20_] Excel Programming 0 January 23rd 04 07:40 PM
macro to apply worksheet event to active worksheet Paul Simon[_2_] Excel Programming 3 August 7th 03 02:50 AM
How name a copied worksheet? David Excel Programming 2 August 5th 03 11:02 PM


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