• 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.

Tracking cell changes in a column onto a 2nd sheet.

Ojan

New Member
Hello all,

I am pulling data from a website that offers it's item database through an API (online game).
So I do this by the Data Tab>From Text> "website api address" and then fill out the other options.
Every hour the website updates it's information, thus I have excel pull the data from the website and put it onto a excel sheet (currently near 25,000 rows with 13 columes, A-M).
I use multiple other sheets with the VLookup function to track certain items.
I would like to track items based on changes in supply and demand volumes, and figure a macro is the way to go as I cannot figure out Excel Functions that can do the same thing.

Currently, the data updates and replaces the information; but I would like to have it keep the last 48-168 values or changes in values. Ideally 168 for a weeks worth of data, but I would like it to disregard values older than 7 days if possible.
So I want columns J and K monitored for changes in the data when it updates. If there is a change in J OR K for that row then have columns A through M reported to a separate sheet. Column J is the number of buy orders for the item while K is the sale supply. I would like the range of the numbers for J and K to be shown.
I'm not sure what the best representation of this data would be though, as I want to track for both numbers going up or down. But doing a Max(#range)-Min(#range) won't tell me if it's a positive or negative change.

Maybe I should just obtain the way to record the data on here then post in the other forum about the best way to utilize the data?

I uploaded the file, having it with the datasaved made the file to large to open so I set the options where it will upload the item database when the file is opened and the external data is removed when the file is closed. Also, the VLookup sheets are not on this file either.

I believe my problem is similar to this recent post: http://chandoo.org/forum/threads/recording-change-in-a-row-in-another-sheet.14162/

Which asks about the following code:
Code:
OptionExplicit
Dim sOldAddress AsString
Dim vOldValue AsVariant
Dim sOldFormula AsString
PrivateSub Workbook_TrackChange(Cancel AsBoolean)

Dim sh As Worksheet
ForEach sh In ActiveWorkbook.Worksheets
sh.PageSetup.LeftFooter = "&06" & ActiveWorkbook.FullName & vbLf & "&A"
Next sh
EndSub
PrivateSub Workbook_SheetChange(ByVal sh AsObject, 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 AsInteger
Set wActSheet = ActiveSheet

'Precursor Exits'Other conditions that you do not want to tracke could be added hereIf vOldValue = ""ThenExitSub'If you comment out this line *every* entry will be recorded
'Continue
OnErrorResumeNext' 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 IsNothingThen
Set wActSheet = ActiveSheet
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Tracker"
EndIf
OnErrorGoTo 0
'**** End of specific error resume next
OnErrorGoToErrorHandler
With Application
.ScreenUpdating = False
.EnableEvents = False
EndWith

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 'IfNot .Cells(65536, iCol) = ""Then'iCol = .Cells(1, 256).End(xlToLeft).Column + 1 'EndIf'EndIf''********* 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
EndIf
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
EndIf

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

'.Protect Password:="Secret" 'Uncomment to protect the "tracker tab"
EndWith
ErrorExit:
With Application
.ScreenUpdating = True
.EnableEvents = True
EndWith

wActSheet.Activate
ExitSub

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

EndSub

PrivateSub Workbook_SheetSelectionChange(ByVal sh AsObject, 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
EndIf
EndIf
EndWith
EndSub

I tried to modify this code to do what I was wanting, but I couldn't make heads from tails of it at all.

Thanks for any help you can give.

-Ojan
 

Attachments

  • Item Database Chandoo Help.xlsx
    757.9 KB · Views: 2
Last edited:
Back
Top