title: Excel VBA code for an audit trail. How to record deletion?
body: <p>I have some code (not mine) for a simple audit logger in Excel that records changes to cells as they occur in a sheet called 'log'. It works fine for all instances, except when a user deletes a cell to leave it blank. In this instance it records nothing. I am not sure why this is. Can anyone help to update the code so that it records when a user deletes the data in a cell to leave a blank? Thank you in advance! James</p>
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
  If Target.Value &lt;&gt; PreviousValue Then
      Sheets(&quot;log&quot;).Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
          Application.UserName &amp; &quot; changed data in cell &quot; &amp; Target.Address _
          &amp; &quot; in sheet &quot; &amp; ActiveSheet.Name &amp; &quot; from &lt;&quot; &amp; PreviousValue &amp; &quot;&gt; to &lt;&quot; &amp; Target.Value &amp; &quot;&gt;&quot; &amp; &quot; at &quot; &amp; Time &amp; &quot; on &quot; &amp; Date
      End If
  End Sub
  
  Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      PreviousValue = Target.Value
  End Sub
  
  
  </code></pre>