#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Worksheet_Change

I have the following code in a worksheet in an EXCEL 2003 file(call it
File1). It seems to work fine if I only have one EXCEL file open. If I have
another EXCEL file open(File2), the code seems to want to execute in that
file also. How to I restrict the code to File1?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range

' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("PJMdata!A1:A1")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then



Range("PJMdata!J1:N1").Select
Selection.Copy
Range("PJMdata!Q2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

Range("PJMdata!A1").Select



End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Worksheet_Change

I don't see any reason why your code should affect another workbook. Since
I cleaned it up in looking it over I thought I'd post my equivalent code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
With Application
.EnableEvents = False
Range("J1:N1").Copy
Range("Q2").End(xlDown).Offset(1).PasteSpecial
Paste:=xlPasteValues
Range("A1").Select
.EnableEvents = True
.CutCopyMode = False
End With
End If
End Sub

Removed some unnecessary stuff like selecting cells. I added
Application.EnableEvents to keep the code itself from firing a change event.

--
Jim
"scrimmy" wrote in message
...
|I have the following code in a worksheet in an EXCEL 2003 file(call it
| File1). It seems to work fine if I only have one EXCEL file open. If I
have
| another EXCEL file open(File2), the code seems to want to execute in that
| file also. How to I restrict the code to File1?
|
| Private Sub Worksheet_Change(ByVal Target As Range)
| Dim KeyCells As Range
|
| ' The variable KeyCells contains the cells that will
| ' cause an alert when they are changed.
| Set KeyCells = Range("PJMdata!A1:A1")
|
| If Not Application.Intersect(KeyCells, Range(Target.Address)) _
| Is Nothing Then
|
|
|
| Range("PJMdata!J1:N1").Select
| Selection.Copy
| Range("PJMdata!Q2").Select
| Selection.End(xlDown).Select
| ActiveCell.Offset(1, 0).Range("A1").Select
| Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
| SkipBlanks _
| :=False, Transpose:=False
|
| Range("PJMdata!A1").Select
|
|
|
| End If
| End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Worksheet_Change

Jim,
Thanks for looking at this.
I tried using your code in my workbook and still have the problem of it
trying to execute in another workbook that I have open.

"Jim Rech" wrote:

I don't see any reason why your code should affect another workbook. Since
I cleaned it up in looking it over I thought I'd post my equivalent code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
With Application
.EnableEvents = False
Range("J1:N1").Copy
Range("Q2").End(xlDown).Offset(1).PasteSpecial
Paste:=xlPasteValues
Range("A1").Select
.EnableEvents = True
.CutCopyMode = False
End With
End If
End Sub

Removed some unnecessary stuff like selecting cells. I added
Application.EnableEvents to keep the code itself from firing a change event.

--
Jim
"scrimmy" wrote in message
...
|I have the following code in a worksheet in an EXCEL 2003 file(call it
| File1). It seems to work fine if I only have one EXCEL file open. If I
have
| another EXCEL file open(File2), the code seems to want to execute in that
| file also. How to I restrict the code to File1?
|
| Private Sub Worksheet_Change(ByVal Target As Range)
| Dim KeyCells As Range
|
| ' The variable KeyCells contains the cells that will
| ' cause an alert when they are changed.
| Set KeyCells = Range("PJMdata!A1:A1")
|
| If Not Application.Intersect(KeyCells, Range(Target.Address)) _
| Is Nothing Then
|
|
|
| Range("PJMdata!J1:N1").Select
| Selection.Copy
| Range("PJMdata!Q2").Select
| Selection.End(xlDown).Select
| ActiveCell.Offset(1, 0).Range("A1").Select
| Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
| SkipBlanks _
| :=False, Transpose:=False
|
| Range("PJMdata!A1").Select
|
|
|
| End If
| End Sub



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Worksheet_Change

still have the problem of it trying to execute in another workbook that I
have open.


Well, I' m sure not making this up but I have no idea how this can possibly
be happening (unless your other workbook is in fact another _window_ of the
same workbook. Nah<g).

--
Jim
"scrimmy" wrote in message
...
| Jim,
| Thanks for looking at this.
| I tried using your code in my workbook and still have the problem of it
| trying to execute in another workbook that I have open.
|
| "Jim Rech" wrote:
|
| I don't see any reason why your code should affect another workbook.
Since
| I cleaned it up in looking it over I thought I'd post my equivalent
code:
|
| Private Sub Worksheet_Change(ByVal Target As Range)
| If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
| With Application
| .EnableEvents = False
| Range("J1:N1").Copy
| Range("Q2").End(xlDown).Offset(1).PasteSpecial
| Paste:=xlPasteValues
| Range("A1").Select
| .EnableEvents = True
| .CutCopyMode = False
| End With
| End If
| End Sub
|
| Removed some unnecessary stuff like selecting cells. I added
| Application.EnableEvents to keep the code itself from firing a change
event.
|
| --
| Jim
| "scrimmy" wrote in message
| ...
| |I have the following code in a worksheet in an EXCEL 2003 file(call it
| | File1). It seems to work fine if I only have one EXCEL file open. If
I
| have
| | another EXCEL file open(File2), the code seems to want to execute in
that
| | file also. How to I restrict the code to File1?
| |
| | Private Sub Worksheet_Change(ByVal Target As Range)
| | Dim KeyCells As Range
| |
| | ' The variable KeyCells contains the cells that will
| | ' cause an alert when they are changed.
| | Set KeyCells = Range("PJMdata!A1:A1")
| |
| | If Not Application.Intersect(KeyCells, Range(Target.Address)) _
| | Is Nothing Then
| |
| |
| |
| | Range("PJMdata!J1:N1").Select
| | Selection.Copy
| | Range("PJMdata!Q2").Select
| | Selection.End(xlDown).Select
| | ActiveCell.Offset(1, 0).Range("A1").Select
| | Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
| | SkipBlanks _
| | :=False, Transpose:=False
| |
| | Range("PJMdata!A1").Select
| |
| |
| |
| | End If
| | End Sub
|
|
|


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Worksheet_Change

I'm sure YOU'RE not making

--
Jim
"Jim Rech" wrote in message
...
| still have the problem of it trying to execute in another workbook that
I
| have open.
|
| Well, I' m sure not making this up but I have no idea how this can
possibly
| be happening (unless your other workbook is in fact another _window_ of
the
| same workbook. Nah<g).
|
| --
| Jim
| "scrimmy" wrote in message
| ...
|| Jim,
|| Thanks for looking at this.
|| I tried using your code in my workbook and still have the problem of it
|| trying to execute in another workbook that I have open.
||
|| "Jim Rech" wrote:
||
|| I don't see any reason why your code should affect another workbook.
| Since
|| I cleaned it up in looking it over I thought I'd post my equivalent
| code:
||
|| Private Sub Worksheet_Change(ByVal Target As Range)
|| If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
|| With Application
|| .EnableEvents = False
|| Range("J1:N1").Copy
|| Range("Q2").End(xlDown).Offset(1).PasteSpecial
|| Paste:=xlPasteValues
|| Range("A1").Select
|| .EnableEvents = True
|| .CutCopyMode = False
|| End With
|| End If
|| End Sub
||
|| Removed some unnecessary stuff like selecting cells. I added
|| Application.EnableEvents to keep the code itself from firing a change
| event.
||
|| --
|| Jim
|| "scrimmy" wrote in message
|| ...
|| |I have the following code in a worksheet in an EXCEL 2003 file(call it
|| | File1). It seems to work fine if I only have one EXCEL file open.
If
| I
|| have
|| | another EXCEL file open(File2), the code seems to want to execute in
| that
|| | file also. How to I restrict the code to File1?
|| |
|| | Private Sub Worksheet_Change(ByVal Target As Range)
|| | Dim KeyCells As Range
|| |
|| | ' The variable KeyCells contains the cells that will
|| | ' cause an alert when they are changed.
|| | Set KeyCells = Range("PJMdata!A1:A1")
|| |
|| | If Not Application.Intersect(KeyCells, Range(Target.Address)) _
|| | Is Nothing Then
|| |
|| |
|| |
|| | Range("PJMdata!J1:N1").Select
|| | Selection.Copy
|| | Range("PJMdata!Q2").Select
|| | Selection.End(xlDown).Select
|| | ActiveCell.Offset(1, 0).Range("A1").Select
|| | Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
|| | SkipBlanks _
|| | :=False, Transpose:=False
|| |
|| | Range("PJMdata!A1").Select
|| |
|| |
|| |
|| | End If
|| | End Sub
||
||
||
|
|




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Worksheet_Change

Thanks again for looking at this. The other workbook is NOT another window
of the same workbook. Could the problem be caused by the web query that I am
using to refresh the data in cell A1? I have the web query set up to run
every 5 minutes and if the value it returns to cell A1 has changed, the code
will execute. As I've said, it works fine unless I am working in another
workbook.

"Jim Rech" wrote:

I'm sure YOU'RE not making


--
Jim
"Jim Rech" wrote in message
...
| still have the problem of it trying to execute in another workbook that
I
| have open.
|
| Well, I' m sure not making this up but I have no idea how this can
possibly
| be happening (unless your other workbook is in fact another _window_ of
the
| same workbook. Nah<g).
|
| --
| Jim
| "scrimmy" wrote in message
| ...
|| Jim,
|| Thanks for looking at this.
|| I tried using your code in my workbook and still have the problem of it
|| trying to execute in another workbook that I have open.
||
|| "Jim Rech" wrote:
||
|| I don't see any reason why your code should affect another workbook.
| Since
|| I cleaned it up in looking it over I thought I'd post my equivalent
| code:
||
|| Private Sub Worksheet_Change(ByVal Target As Range)
|| If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
|| With Application
|| .EnableEvents = False
|| Range("J1:N1").Copy
|| Range("Q2").End(xlDown).Offset(1).PasteSpecial
|| Paste:=xlPasteValues
|| Range("A1").Select
|| .EnableEvents = True
|| .CutCopyMode = False
|| End With
|| End If
|| End Sub
||
|| Removed some unnecessary stuff like selecting cells. I added
|| Application.EnableEvents to keep the code itself from firing a change
| event.
||
|| --
|| Jim
|| "scrimmy" wrote in message
|| ...
|| |I have the following code in a worksheet in an EXCEL 2003 file(call it
|| | File1). It seems to work fine if I only have one EXCEL file open.
If
| I
|| have
|| | another EXCEL file open(File2), the code seems to want to execute in
| that
|| | file also. How to I restrict the code to File1?
|| |
|| | Private Sub Worksheet_Change(ByVal Target As Range)
|| | Dim KeyCells As Range
|| |
|| | ' The variable KeyCells contains the cells that will
|| | ' cause an alert when they are changed.
|| | Set KeyCells = Range("PJMdata!A1:A1")
|| |
|| | If Not Application.Intersect(KeyCells, Range(Target.Address)) _
|| | Is Nothing Then
|| |
|| |
|| |
|| | Range("PJMdata!J1:N1").Select
|| | Selection.Copy
|| | Range("PJMdata!Q2").Select
|| | Selection.End(xlDown).Select
|| | ActiveCell.Offset(1, 0).Range("A1").Select
|| | Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
|| | SkipBlanks _
|| | :=False, Transpose:=False
|| |
|| | Range("PJMdata!A1").Select
|| |
|| |
|| |
|| | End If
|| | End Sub
||
||
||
|
|



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Worksheet_Change

I don't do many web queries so I don't know if it might be causing this.

If you have another workbook open and manually make an entry in A1 does the
problem occur?

--
Jim
"scrimmy" wrote in message
...
Thanks again for looking at this. The other workbook is NOT another
window
of the same workbook. Could the problem be caused by the web query that I
am
using to refresh the data in cell A1? I have the web query set up to run
every 5 minutes and if the value it returns to cell A1 has changed, the
code
will execute. As I've said, it works fine unless I am working in another
workbook.

"Jim Rech" wrote:

I'm sure YOU'RE not making


--
Jim
"Jim Rech" wrote in message
...
| still have the problem of it trying to execute in another workbook
that
I
| have open.
|
| Well, I' m sure not making this up but I have no idea how this can
possibly
| be happening (unless your other workbook is in fact another _window_ of
the
| same workbook. Nah<g).
|
| --
| Jim
| "scrimmy" wrote in message
| ...
|| Jim,
|| Thanks for looking at this.
|| I tried using your code in my workbook and still have the problem of
it
|| trying to execute in another workbook that I have open.
||
|| "Jim Rech" wrote:
||
|| I don't see any reason why your code should affect another workbook.
| Since
|| I cleaned it up in looking it over I thought I'd post my equivalent
| code:
||
|| Private Sub Worksheet_Change(ByVal Target As Range)
|| If Not Application.Intersect(Range("A1"), Target) Is Nothing
Then
|| With Application
|| .EnableEvents = False
|| Range("J1:N1").Copy
|| Range("Q2").End(xlDown).Offset(1).PasteSpecial
|| Paste:=xlPasteValues
|| Range("A1").Select
|| .EnableEvents = True
|| .CutCopyMode = False
|| End With
|| End If
|| End Sub
||
|| Removed some unnecessary stuff like selecting cells. I added
|| Application.EnableEvents to keep the code itself from firing a
change
| event.
||
|| --
|| Jim
|| "scrimmy" wrote in message
|| ...
|| |I have the following code in a worksheet in an EXCEL 2003 file(call
it
|| | File1). It seems to work fine if I only have one EXCEL file open.
If
| I
|| have
|| | another EXCEL file open(File2), the code seems to want to execute
in
| that
|| | file also. How to I restrict the code to File1?
|| |
|| | Private Sub Worksheet_Change(ByVal Target As Range)
|| | Dim KeyCells As Range
|| |
|| | ' The variable KeyCells contains the cells that will
|| | ' cause an alert when they are changed.
|| | Set KeyCells = Range("PJMdata!A1:A1")
|| |
|| | If Not Application.Intersect(KeyCells, Range(Target.Address)) _
|| | Is Nothing Then
|| |
|| |
|| |
|| | Range("PJMdata!J1:N1").Select
|| | Selection.Copy
|| | Range("PJMdata!Q2").Select
|| | Selection.End(xlDown).Select
|| | ActiveCell.Offset(1, 0).Range("A1").Select
|| | Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
|| | SkipBlanks _
|| | :=False, Transpose:=False
|| |
|| | Range("PJMdata!A1").Select
|| |
|| |
|| |
|| | End If
|| | End Sub
||
||
||
|
|





  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Worksheet_Change

I believe have found a way around my problem. It seems that if I want to
work with other EXCEL files while the file in question is open, I have to
physically open a separate session of EXCEL. This is a bit of nuisance and
doesn't answer the question of why the code tries to run in other files, but
it gets me past my problem. Thank you again for looking into this. Your
help is greatly appreciated.

"Jim Rech" wrote:

I don't do many web queries so I don't know if it might be causing this.

If you have another workbook open and manually make an entry in A1 does the
problem occur?

--
Jim
"scrimmy" wrote in message
...
Thanks again for looking at this. The other workbook is NOT another
window
of the same workbook. Could the problem be caused by the web query that I
am
using to refresh the data in cell A1? I have the web query set up to run
every 5 minutes and if the value it returns to cell A1 has changed, the
code
will execute. As I've said, it works fine unless I am working in another
workbook.

"Jim Rech" wrote:

I'm sure YOU'RE not making

--
Jim
"Jim Rech" wrote in message
...
| still have the problem of it trying to execute in another workbook
that
I
| have open.
|
| Well, I' m sure not making this up but I have no idea how this can
possibly
| be happening (unless your other workbook is in fact another _window_ of
the
| same workbook. Nah<g).
|
| --
| Jim
| "scrimmy" wrote in message
| ...
|| Jim,
|| Thanks for looking at this.
|| I tried using your code in my workbook and still have the problem of
it
|| trying to execute in another workbook that I have open.
||
|| "Jim Rech" wrote:
||
|| I don't see any reason why your code should affect another workbook.
| Since
|| I cleaned it up in looking it over I thought I'd post my equivalent
| code:
||
|| Private Sub Worksheet_Change(ByVal Target As Range)
|| If Not Application.Intersect(Range("A1"), Target) Is Nothing
Then
|| With Application
|| .EnableEvents = False
|| Range("J1:N1").Copy
|| Range("Q2").End(xlDown).Offset(1).PasteSpecial
|| Paste:=xlPasteValues
|| Range("A1").Select
|| .EnableEvents = True
|| .CutCopyMode = False
|| End With
|| End If
|| End Sub
||
|| Removed some unnecessary stuff like selecting cells. I added
|| Application.EnableEvents to keep the code itself from firing a
change
| event.
||
|| --
|| Jim
|| "scrimmy" wrote in message
|| ...
|| |I have the following code in a worksheet in an EXCEL 2003 file(call
it
|| | File1). It seems to work fine if I only have one EXCEL file open.
If
| I
|| have
|| | another EXCEL file open(File2), the code seems to want to execute
in
| that
|| | file also. How to I restrict the code to File1?
|| |
|| | Private Sub Worksheet_Change(ByVal Target As Range)
|| | Dim KeyCells As Range
|| |
|| | ' The variable KeyCells contains the cells that will
|| | ' cause an alert when they are changed.
|| | Set KeyCells = Range("PJMdata!A1:A1")
|| |
|| | If Not Application.Intersect(KeyCells, Range(Target.Address)) _
|| | Is Nothing Then
|| |
|| |
|| |
|| | Range("PJMdata!J1:N1").Select
|| | Selection.Copy
|| | Range("PJMdata!Q2").Select
|| | Selection.End(xlDown).Select
|| | ActiveCell.Offset(1, 0).Range("A1").Select
|| | Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
|| | SkipBlanks _
|| | :=False, Transpose:=False
|| |
|| | Range("PJMdata!A1").Select
|| |
|| |
|| |
|| | End If
|| | 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
Worksheet_Change help Soundman Excel Discussion (Misc queries) 3 June 30th 06 10:46 PM
Worksheet_Change - NEW to VBA [email protected] Excel Worksheet Functions 1 April 26th 06 05:44 PM
Getting around Worksheet_Change() mtowle Excel Worksheet Functions 1 October 20th 05 06:05 PM
Problems with "Worksheet_Change" konpego Excel Discussion (Misc queries) 0 July 5th 05 06:29 AM
Worksheet_change won't run Eric Excel Discussion (Misc queries) 4 March 10th 05 03:43 PM


All times are GMT +1. The time now is 11:13 PM.

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"