Search code examples
vbaexcelworksheet-functionworksheet

Get the old value in a Worksheet_Change Target


I have an Excelsheet with 2 columns. The second column must only contain values which are also in the first column. If a value in the first column changes I have to replace all its occurrences in the second column. There is a Worksheet_Change event which is called if a worksheet changes but unfortunately I can't find a way to get the old value of a changed cell.

Is it possible to find out the old value of a cell?


Solution

  • Edit: I read your question wrong, here's to get your old value before selection change

    Dim oldValue As Variant
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        oldValue = Target.Value
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        'Do whatever you need to do.
    End Sub