Workbook_SheetChange - Track Old Value

Andresuru

New Member
Joined
Sep 6, 2021
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hello Team,

Appreciate your help with guidance,

I already have a vba code to track date, new value, username etc but I need to track the old value. I tried to track using workbook?selectionchange however is not working and is very important to track the old value.


VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim LR As Long
Dim Oval As String

If Sh.Name = "Historial" Then Exit Sub

Application.EnableEvents = False

With Sheets("Historial")

    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LR + 1).Value = Format(Now, "dd-mm-yy hh:mm:ss")
    .Range("B" & LR + 1).Value = Sh.Name
    .Range("C" & LR + 1).Value = Target.Address(False, False)
    .Range("D" & LR + 1).Value = Target.Value
    .Range("E" & LR + 1).Value = Environ("USERNAME")
    .Range("F" & LR + 1).Value = Oval
    
End With

Application.EnableEvents = True

End Sub

Public Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

Oval = Target.Value

End Sub

Apreciate a lot your help on this.

Regards
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Oval needs to be declared at module level, not procedure level.

Basically I am not sure how to use oval, I just found somewhere in google and try to adapt but i have seing there are many people with same situation and most of the times are getting error.
So if you can help me to see VBA code that can be added to my macro, appreciated.

Regards
 
Upvote 0
So if you can help me to see VBA code that can be added to my macro, appreciated.
It is in the link that I provided, you have used the first method but you need to use the second one.

Move the line that says Dim Oval As String so that it is above the Private Sub line and it should work fine.
 
Upvote 0
Solution
Hello Team,

Appreciate your help with guidance,

I already have a vba code to track date, new value, username etc but I need to track the old value. I tried to track using workbook?selectionchange however is not working and is very important to track the old value.

Track the old value of what?
 
Upvote 0
It is in the link that I provided, you have used the first method but you need to use the second one.

Move the line that says Dim Oval As String so that it is above the Private Sub line and it should work fine.

That's resolved the issue, thank you a lot, MOD you can close this thread.

Regards
 
Upvote 0

Forum statistics

Threads
1,215,757
Messages
6,126,693
Members
449,331
Latest member
smckenzie2016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top