Another change event question
Paolo,
You can have it worksheet, workbook or even application related, but it
depends upon what is wanted.
Actually, you don't need to create a class module, put it in the
ThisWorkbook module, which is a class module, and you don't need to
instantiate the class (ThisWorkbook is implicitly instantiated).
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Paolo De Laurentiis" wrote in message
...
Hi Bob,
your way is exactly what I'm using to track changes to an excel worksheet.
Actually, you can have it non "worksheet related", but "application
related", just writing a class module of the Application object.
Write this in a class module:
Public WithEvents App As Application
Private Sub App_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)
'store previous value here
End Sub
Private Sub App_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'read changed value here
End Sub
Then set a variable in a module to the class object:
dim x as ClassModuleName
Set x.App = Application
Then you're done.
However, this is not perfect... please have a look to my posting:
"Posting again. Please Help! How to "track changes" using VBA"
Paolo
"Bob Phillips" ha scritto nel
messaggio
...
Oh yes! Here is an example
Option Explicit
Dim oldVal
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
MsgBox "You changed: " & .Address(False, False) & " from " &
oldVal
& _
" to " & .Value
oldVal = .Value
End With
ws_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
oldVal = Target.Value
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
RP
(remove nothere from the email address if mailing direct)
"Steph" wrote in message
...
Can I somehow capture what the cell value was before it was changed?
I know I can capture the cell changed and the changed value in the
following:
MsgBox "You changed: " & Target.Address & " to " & Target.Value
I would love it to tell me You changed A1 from 15 to 25
Possible?
|