Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50178

Worksheet Change VBA

$
0
0
Hi, I am certainly no expert at VBA but got a change macro from this site which has been very useful. The thing is I am try to log changes on a worksheet were the formatting can change frequently. The main issue is that the colour of a row has to be changed when a change is made but on the log sheet for this when the colour is changed it can put reams and reams of data in the log which is completely useless to me. All i need it to do is record when a single cell is changed as this will give me the changes i need. Can anyone advise how this can be done in the VBA code I use so that if a cell colour is changed it is not giving me lines and lines of useless data?

Here is the code I am using:


Code:

Dim PreviousValue
 
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Target.Rows.Count > 1 Or Target.Columns.Count > 1 Then
       
        For Each thecell In Target
            Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
                Application.UserName & " changed cell " & Target.Address _
                & " to " & thecell.Value
        Next
        Exit Sub
       
    End If
 
  If Target.Value <> PreviousValue Then
 
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = Cells(Target.Row, 1).Value
           
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(0, 1).Value = Application.UserName
       
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(0, 2).Value = Cells(5, Target.Column).Value
       
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(0, 3).Value = PreviousValue
       
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(0, 4).Value = Target.Value
       
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(0, 5).Value = Now()
       
    End If
   

End Sub


Thanks in advance fo

Viewing all articles
Browse latest Browse all 50178

Trending Articles