Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change Event that Loops

I have code which triggers off a Change Event in a Sheet. When I chang
a cell in the spreadsheet, the code copies and pastes a range withi
this sheet to another range. The problem is that once the copy/past
engages, the code continues be called and loops on continuously. Ho
do I trigger a copy/paste using the Change Event without looping? I
my only option to copy/paste to a new sheet?


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer


Export = Range("DropDownExport")

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")


End Select


End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change Event that Loops

I think what is happening is that I need to restrict the change event t
the specific cell that I want to see the change in. The way the cod
is written, it triggers based on a change anywhere in the spreadsheet.
The change that needs to be tracked is
Range("DropDownExport")

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change Event that Loops

I think I just answered my own question. This code below seems to work



Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer
Dim VRange As Range


Export = Range("DropDownExport")

Set VRange = Range("DropDownExport")
If Union(Target, VRange).Address = VRange.Address Then

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")

End Select

End If


End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Change Event that Loops

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer

Application.EnableEvents = False
On Error GoTo ws_exit
Export = Range("DropDownExport")

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")

End Select

ws_exit:
Application.EnableEvents = True
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"ExcelMonkey " wrote in message
...
I have code which triggers off a Change Event in a Sheet. When I change
a cell in the spreadsheet, the code copies and pastes a range within
this sheet to another range. The problem is that once the copy/paste
engages, the code continues be called and loops on continuously. How
do I trigger a copy/paste using the Change Event without looping? Is
my only option to copy/paste to a new sheet?


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer


Export = Range("DropDownExport")

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")


End Select


End Sub


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change Event that Loops

Another question. I have put a line just under the variabl
declarations which seems to stall the code:

Range("DynamicNameRange").ClearContents

I can't figure out why this does not work. When I use this line o
code by itself in a stand-alone module it works fine.




Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer
Dim VRange As Range

Range("DynamicNameRange").ClearContents

Export = Range("DropDownExport")

Set VRange = Range("DropDownExport")
If Union(Target, VRange).Address = VRange.Address Then

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")


End Select

End If


End Su

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Change Event that Loops

Monkey,

That looks right. FYI, you can also disable and enable events to prevent
the looping. For instance:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer

Application.EnableEvents = False 'turns off events so no looping

Export = Range("DropDownExport")
Select Case Export
Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")
End Select

Application.EnableEvents = True

End Sub

hth,

Doug Glancy
"ExcelMonkey " wrote in message
...
I think I just answered my own question. This code below seems to work.



Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer
Dim VRange As Range


Export = Range("DropDownExport")

Set VRange = Range("DropDownExport")
If Union(Target, VRange).Address = VRange.Address Then

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")

End Select

End If


End Sub


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Change Event that Loops

Monkey,

Looks like you've put yourself back into a loop. Clearing contents would be
a change, I think. So, either put the clearcontents inside your if
statement, or set enableevents to false.

hth,

Doug Glancy

"ExcelMonkey " wrote in message
...
Another question. I have put a line just under the variable
declarations which seems to stall the code:

Range("DynamicNameRange").ClearContents

I can't figure out why this does not work. When I use this line of
code by itself in a stand-alone module it works fine.




Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Export As Integer
Dim VRange As Range

Range("DynamicNameRange").ClearContents

Export = Range("DropDownExport")

Set VRange = Range("DropDownExport")
If Union(Target, VRange).Address = VRange.Address Then

Select Case Export

Case Is = 1
Range("FuelTypeName").Copy Destination:=Range("NamePaste")


End Select

End If


End Sub


---
Message posted from http://www.ExcelForum.com/



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
change event smonsmo Excel Discussion (Misc queries) 1 June 8th 07 09:31 PM
Change of Row event crazybass2 Excel Discussion (Misc queries) 7 December 7th 04 06:21 PM
Chart Values that change based on Change event ExcelMonkey[_119_] Excel Programming 1 May 15th 04 03:43 AM
Change minimumscale with the change event of a combobox Herbert Chan Excel Programming 1 April 11th 04 12:43 PM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM


All times are GMT +1. The time now is 04:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"