Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help - track changes code needs tweaking


Hiya folks!

I got this code from ozgrid.com and modified it slightly to meet my needs
however there is one thing that I need to do and I can't seem to get it
right. When a user deletes many cells at once the results are "empty cell"
in the new value field but a null string in the old value field (with the
exception of the first cell selected). I tried another 'if then' and
imbedded a 'for each' statement when x (the number of cells selected) is
greater than 1 but its not quite right. Is there a way to do this or will I
have to reference the sheet that I am tracking this info on to get the old
value?


I really hope this makes sense. Here is a sample of what this code does:




Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)

If sh.Name = "Sheet4" Then Exit Sub

x = Target.Cells.Count
MsgBox (x)
For Each Target In Range(Target.Address).Cells

If IsEmpty(vOldVal) Then vOldVal = "Empty Cell"

On Error Resume Next


Application.EnableEvents = False
With Sheet4

.Protect Password:="Secret", UserInterFaceOnly:=True
.Cells(1, 1) = "CELL CHANGED"
.Cells(65536, 1).End(xlUp)(2, 1) = Target.Address
.Cells(1, 2) = "OLD VALUE"
.Cells(65536, 2).End(xlUp)(2, 1) = vOldVal
With .Cells(1, 3)
.Value = "NEW VALUE"
.ClearComments
End With
With .Cells(65536, 3).End(xlUp)(2, 1)

.Value = Target.Value



If IsEmpty(Target) Or 0 Then .Value = "Empty Cell"
.Font.Bold = bBold
End With
.Cells(1, 4) = "TIME OF CHANGE"
.Cells(65536, 4).End(xlUp)(2, 1) = Time
.Cells(1, 5) = "DATE OF CHANGE"
.Cells(65536, 5).End(xlUp)(2, 1) = Date
.Cells(1, 6) = "SHEET"
.Cells(65536, 6).End(xlUp)(2, 1) = sh.Name
.Cells(1, 7) = "FORMULA"
If Target.HasFormula Then
.Cells(65536, 7).End(xlUp)(2, 1) = " '" & Target.Formula & "'"
Else
.Cells(65536, 7).End(xlUp)(2, 1) = " "
End If
.Cells(1, 8) = "CELL OR RANGE"
If x = 1 Then
.Cells(65536, 8).End(xlUp)(2, 1) = "Cell"
Else
.Cells(65536, 8).End(xlUp)(2, 1) = "Range"
End If
.Cells.Columns.AutoFit
End With
vOldVal = vbNullString
Application.EnableEvents = True
On Error GoTo 0
Next

End Sub

Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target
As Range)

For Each Target In Range(Target.Address).Cells


vOldVal = Target.Value


Next


End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping track of code Eric White[_2_] Excel Programming 4 June 9th 05 09:41 AM
Tweaking Code - Experts Only! Gordon Excel Programming 4 August 6th 04 04:09 PM
combining 2+ wkbks into 1. Code needs tweaking please ian123[_31_] Excel Programming 12 January 3rd 04 11:20 PM
Searching range for value (code written but needs 'tweaking'!) ian123[_26_] Excel Programming 8 December 23rd 03 05:19 PM
Highlight Track Changes with VBA Code? Garp Excel Programming 1 December 23rd 03 01:32 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"