Solved

Excel: VBA tracking. (VBA updates any changes made to worksheet.)

Posted on 2010-09-19
2
224 Views
Last Modified: 2012-05-10
Normally I use Tools-->Track Changes --->Highlight Changes.

As you know this will show a note on each cell that is changed with the following information...

1) The users name
2) Time user made the change
3) A description of the change.

I would like to create VBA that does something similar. (I don't want to use "Track Changes"...)

Therefore....What VBA would I need so that every time a user makes a change to "Sheet1" of my Excel file, on Sheet 2 column A it will log in a cell the users name/computer name, current date and if possible the first 20 characters of the change.

i.e. if the user named "Bobby" goes to "Sheet1" and updates cell C1 to "Hello on 6/7/10" then updates cell E20 to "goodbye" on 8/1/10
the following information will show on "Sheet2" in columnA

         column A
Row1: 6/7/10, Bobby, "Hello"
Row2: 8/1/10, Bobby, "goodbye"



0
Comment
Question by:ouestque
  • 2
2 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 33713256
  • right click your sheet1 sheet tab
  • View - Code
  • copy and paste the code below
This code will handle multiple cell updates at once, plus it returns the logged on username - not the username entered as an Option in Excel which users can change

Note that you need to change the Sheet2 name if the second sheet is renamed

Cheers

Dave

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    Dim c As Range
    Set ws = ThisWorkbook.Sheets("Sheet2")
    For Each c In Target
        If Not ws.[a1] = vbNullString Then
            ws.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = Format(Now(), "d/mm/yy, ") & Environ("username") & ", " & c.Value
        Else
            ws.[a1] = Format(Now(), "d/mm/yy, ") & Environ("username") & ", " & c.Value
        End If
    Next c
End Sub

Open in new window

0
 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 total points
ID: 33713266
If you wanted to capture the cell address being changed then use

Format(Now(), "d/mm/yy, ") & Environ("username") & ", " & c.Address(0, 0) & ", " & c.Value
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question