Solved

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

Posted on 2010-09-19
2
223 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

831 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