View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
scottydel scottydel is offline
external usenet poster
 
Posts: 23
Default Worksheet Change Event question

Thanks for the replies. Bob I used your sample code, and am having some
issues. I have the following code, which is supposed to copy data from a
cell on one sheet to a corresponding cell on another sheet (shifted left one
column and up one row on the sheet I am pasting to).

My code works sometimes, and sometimes has no effect at all (setting a
break-point doesn't even step in to the code). Pretty confused.

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_Exit

Excel.Application.EnableEvents = False
Target.Copy

UnProtectSheet "Master Data"
Worksheets("Master Data").Cells(Target.Row - 1, Target.Column -
1).PasteSpecial xlPasteValues, _

xlPasteSpecialOperationNone, _

False, _

False
Target.Select
ProtectSheet "Master Data"

ws_Exit:
Excel.Application.EnableEvents = True

End Sub

"Bob Phillips" wrote:

If you use the Workseheet_Change event, Excel passes the changed range to
the evnt, which is tested as the Target argument.

This is a skeleton example of code to test and handle this

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
' do your stuff
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"scottydel" wrote in message
...
Hello,

I'm using Excel 2003. The woksheet change event fires when any data on
the
worksheet changes. Does anyone know a way to determine which specifc cell
(or range I suppose) has changed?

Thanks,

Scott