• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Recording change in a row, in another sheet

Bhushan

New Member
Hi..

I have a query

There are 100 Rows in the table
Column A & B, are through webquery, With Column B Changing every 30 seconds.
Column C is a manual entry value and will remain constant.
Column D is a IF formula

Macro Required is:
When There is change in cell is Column D, the entire row with Time to be recorded in Sheet2

For instance, if D5 gets the value "Target Achieved", Then entire D row to be recorded in sheet2
after some time if B5 gets the value " Target Achieved", Then entire B row to be recorded in Sheet 2

Thanks
Bhushan

attached excel sheet for better explanation.
 

Attachments

  • ChangeRec.xls
    28.5 KB · Views: 6
Last edited:
Hi..
P.S.: The work of Sheet2, is like a log book. So all changes have to be recorded one by one. in Sheet2
 
Hi, Bhushan!

Since column D has a formula and Excel only traps change events in cells based on manual input (neither copy & paste nor formula changes), you won't be able to detect column D changes but maybe you'd succeed with the dependent cells using in D formula, that BTW which is it?

Regards!
 
Hi SirJB7..

I got this below code from another forum (credit of code to arkusM), which records even formula changes

Place this code in "ThisWorkbook"
It will track all changes made anywher in the workbook and places the changes on a tab called "tracker" it also tracks formula changes.

I am not that much familiar of how to make the necessary changes for my use. Please kindly help.
thanks,
Bhushan

Code:
Option Explicit
Dim sOldAddress As String
Dim vOldValue As Variant
Dim sOldFormula As String
Private Sub Workbook_TrackChange(Cancel As Boolean)

Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.PageSetup.LeftFooter = "&06" & ActiveWorkbook.FullName & vbLf & "&A"
Next sh
End Sub
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
'''''''''''''''''''''''''''''''''''''''''''''
'Thanks to lenze for getting me started on this project ([URL]http://vbaexpress.com/kb/getarticle.php?kb_id=909[/URL] )
'http://www.mrexcel.com/forum/showthread.php?t=376400&referrerid=76744 'Thanks to Colin_L
'Adapted by Mark Reierson 2009
'''''''''''''''''''''''''''''''''''''''''''''

Dim wSheet As Worksheet
Dim wActSheet As Worksheet
Dim iCol As Integer
Set wActSheet = ActiveSheet

'Precursor Exits
'Other conditions that you do not want to tracke could be added here
If vOldValue = "" Then Exit Sub 'If you comment out this line *every* entry will be recorded

'Continue

On Error Resume Next ' This Error-Resume-Next is only to allow the creation of the tracker sheet.
Set wSheet = Sheets("Tracker")
'**** Add the tracker Sheet if it does not exist ****

If wSheet Is Nothing Then
Set wActSheet = ActiveSheet
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Tracker"
End If
On Error GoTo 0
'**** End of specific error resume next

On Error GoTo ErrorHandler
With Application
.ScreenUpdating = False
.EnableEvents = False
End With

With Sheets("Tracker")
'******** This bit of code moves the tracker over a column when the first columns are full**'
If .Cells(1, 1) = "" Then '
iCol = 1 '
Else '
iCol = .Cells(1, 256).End(xlToLeft).Column - 7 '
If Not .Cells(65536, iCol) = "" Then '
iCol = .Cells(1, 256).End(xlToLeft).Column + 1 '
End If '
End If '
'********* END *****************************************************************************'
.Unprotect Password:="Secret"

'******** Sets the Column Headers **********************************************************
If LenB(.Cells(1, iCol).Value) = 0 Then
.Range(.Cells(1, iCol), .Cells(1, iCol + 7)) = Array("Cell Changed", "Old Value", _
"New Value", "Old Formula", "New Formula", "Time of Change", "Date of Change", "User")
.Cells.Columns.AutoFit
End If
With .Cells(.Rows.Count, iCol).End(xlUp).Offset(1)

.Value = sOldAddress
.Offset(0, 1).Value = vOldValue
.Offset(0, 3).Value = sOldFormula

If Target.Count = 1 Then
.Offset(0, 2).Value = Target.Value
If Target.HasFormula Then .Offset(0, 4).Value = "'" & Target.Formula
End If

.Offset(0, 5) = Time
.Offset(0, 6) = Date
.Offset(0, 7) = Application.UserName
.Offset(0, 7).Borders(xlEdgeRight).LineStyle = xlContinuous
End With

'.Protect Password:="Secret" 'Uncomment to protect the "tracker tab"

End With
ErrorExit:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With

wActSheet.Activate
Exit Sub

ErrorHandler:
'any error handling you want
'Debug.Print "We have an error"
Resume ErrorExit

End Sub

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

With Target
sOldAddress = .Address(external:=True)

If .Count > 1 Then

vOldValue = "Multiple Cell Select"
sOldFormula = vbNullString

Else

vOldValue = .Value
If .HasFormula Then
sOldFormula = "'" & Target.Formula
Else
sOldFormula = vbNullString
End If
End If
End With
End Sub
 
Hi, Bhushan!
Thanks for posting that code, I haven't seen it before or at least I don't remember. In the next days I'll give it a try and come back to tell you what I found and if it's suitable for your requirement.
Regards!
 
Hi Bhushan,

Try the below code on the Sheet1 code module.

The below code executes while any value gets changed on the sheet1 and checks if the 4th column of the value changed row has the text "Target Achieved". If so, it copies the entire row data to the sheet2.

Note that the code counter the row number on the Sheet2!A1 Cell. This holds the row number to paste on. It starts with the 3rd row number and adds up as the rows get logged.

Give a try and let me know, if this helps. Thanks.

Code:
 Private Sub Worksheet_Change(ByVal Target As Range)
    If ActiveWorkbook.Sheets("Sheet2").Range("A1").Text = "" Then ActiveWorkbook.Sheets("Sheet2").Range("A1") = 3

    If Cells(Target.Row, 4) = "Target Achieved" Then
        Rows(Target.Row).Copy
        ActiveWorkbook.Sheets("Sheet2").Activate
        ActiveSheet.Rows(ActiveSheet.Range("A1").Value).Select
        Selection.PasteSpecial Paste:=xlPasteValues
        ActiveSheet.Range("A1").Value = ActiveSheet.Range("A1").Value + 1
        ActiveWorkbook.Sheets("Sheet1").Activate
        Application.CutCopyMode = False
    End If
End Sub
 
Hi Lohithsriram,

I tried the code.
This works well, if there is a manual change in Sheet1,

But my project, data is automatic from a webquery. hence the Worksheet_change function does not work.

Would there be any other method?

Regards,
Bhushan
 
Hi Bhushan,

How is the data getting updated? Is that on a regular interval triggered by Excel event ? or using RTD formula? or any other method. There has to be some trigger or a interval to refresh the data.
 
Hi Lohithsriram,

Data in B1 is through webquery, updating almost every 30 seconds.
Cell D1 is a IF formula

If the formula in D1 is satisfied, E1 cell becomes "Target Achieved".

Further, This E1 can change back to blank if the D1 formula is not met due to changes in B1.

Hence there is no manual entry at any point of time, all changes are through webquery only.

thanks,
Bhushan
 
Back
Top