Exclude Cell Range from Worksheet_Change function

BenC

I'm currently trying to set up a spread sheet which will allow me to keep a track of each time someone in the office changes any information within it, I have got this to work via the following code:-

Dim PreviousValue

 Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Value <> PreviousValue Then
    Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
        Application.UserName & " changed cell " & Target.Address _
        & " from " & PreviousValue & " to " & Target.Value
  End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 PreviousValue = Target.Value
End Sub

Which logs any changes to all the cells in the workbook. However I also have this code:-

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
 Sheets("MEP 01").Range("D5").Value = Date
 Sheets("MEP 01").Range("E5").Value = Time
End Sub

This then logs the last time the document was saved, I would like to know if there is any way I can remove cells D5 and E5 from the audit code, as these two cells along with D4 (which contains =TODAY() formula) will change often and will make my audit trail rather large.

Any help would be most appreciated.

Mark Fitzgerald

In your Workbook_BeforeSave add:

Application.EnableEvents = False

before changing the sheets but be sure to add

Application.EnableEvents = True

before ending the Sub.

This prevents the Worksheet_Change event from being triggered so nothing gets written to your log.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

From Dev

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

From Dev

Combining Select Case as Cell and Range in Worksheet_Change

From Dev

Exclude cell value from rank range based on value in another cell

From Dev

How to exclude ranges overlap from a range ? (Move cell contents macro)

From Dev

Copy the value from a cell in a worksheet into a range of cells

From Dev

Worksheet_Change setting target range is slow

From Dev

Expanding Worksheet_Change to Numerous Range Values

From Dev

create new worksheet after cell (in a range) change

From Dev

Function accessing cell range

From Dev

VBA: From all worksheet containing value in cell paste range

From Dev

Stop a 'worksheet_change' or worksheet_calculate from running

From Dev

How to manually modify a cell that is being edited in a worksheet_change event?

From Dev

Multiple worksheet_change with same macro with different reference cell

From Dev

Return a range from a cell's address in an VBA function?

From Dev

Concatenating text from one cell into a function's range

From Dev

Worksheet_Change(ByVal Target As Range), Target always equals Nothing

From Dev

Get Cell From Range

From Dev

Exclude one row from range

From Dev

Exclude an escaped character from a range

From Dev

Excel VBA Worksheet change, entering a range instead of one cell

From Dev

How to unable Worksheet_Change from Excel VBA if Macro is enabled

From Dev

Excel 2010: How to Run FUNCTION procedures in a cell on another range of cell change?

From Dev

Exclude Range of Numbers from a given Range (Port Range)

From Dev

Exclude Range of Numbers from a given Range (Port Range)

From Dev

call function to each cell in a range (involve insert rows, so the range will change) in Excel VBA

From Dev

Copy cell range from one worksheet and paste in a different worksheet as a value rather than formula

From Dev

How to assign value from a named range in one worksheet to a cell in the active worksheet?

From Dev

Remove cell from Range (object)

Related Related

  1. 1

    Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

  2. 2

    Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

  3. 3

    Combining Select Case as Cell and Range in Worksheet_Change

  4. 4

    Exclude cell value from rank range based on value in another cell

  5. 5

    How to exclude ranges overlap from a range ? (Move cell contents macro)

  6. 6

    Copy the value from a cell in a worksheet into a range of cells

  7. 7

    Worksheet_Change setting target range is slow

  8. 8

    Expanding Worksheet_Change to Numerous Range Values

  9. 9

    create new worksheet after cell (in a range) change

  10. 10

    Function accessing cell range

  11. 11

    VBA: From all worksheet containing value in cell paste range

  12. 12

    Stop a 'worksheet_change' or worksheet_calculate from running

  13. 13

    How to manually modify a cell that is being edited in a worksheet_change event?

  14. 14

    Multiple worksheet_change with same macro with different reference cell

  15. 15

    Return a range from a cell's address in an VBA function?

  16. 16

    Concatenating text from one cell into a function's range

  17. 17

    Worksheet_Change(ByVal Target As Range), Target always equals Nothing

  18. 18

    Get Cell From Range

  19. 19

    Exclude one row from range

  20. 20

    Exclude an escaped character from a range

  21. 21

    Excel VBA Worksheet change, entering a range instead of one cell

  22. 22

    How to unable Worksheet_Change from Excel VBA if Macro is enabled

  23. 23

    Excel 2010: How to Run FUNCTION procedures in a cell on another range of cell change?

  24. 24

    Exclude Range of Numbers from a given Range (Port Range)

  25. 25

    Exclude Range of Numbers from a given Range (Port Range)

  26. 26

    call function to each cell in a range (involve insert rows, so the range will change) in Excel VBA

  27. 27

    Copy cell range from one worksheet and paste in a different worksheet as a value rather than formula

  28. 28

    How to assign value from a named range in one worksheet to a cell in the active worksheet?

  29. 29

    Remove cell from Range (object)

HotTag

Archive