+ Reply to Thread
Results 1 to 10 of 10

On Value Change Copy Data To Another Sheet

Hybrid View

Roth On Value Change Copy Data To... 11-05-2009, 08:16 AM
DonkeyOte Re: On Value Change Copy Data... 11-05-2009, 09:28 AM
Roth Re: On Value Change Copy Data... 11-05-2009, 10:07 AM
DonkeyOte Re: On Value Change Copy Data... 11-05-2009, 11:12 AM
Roth Re: On Value Change Copy Data... 11-05-2009, 11:25 AM
  1. #1
    Registered User
    Join Date
    10-28-2009
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    6

    On Value Change Copy Data To Another Sheet

    Hi All,

    New to this site and VB ability is only fair. I have a sheet in Excel (sheet 1)which reads in eleven values. If the data in the 11th value changes then I would like to copy the other 10 values to sheet 2 appending to previous values copied. Date and time on each copy would also be nice if possible.

    The values in sheet 1 are being read in via an OPC server from a machine and only change at the and of a batch which could take a few hours.

    We are trying to gather this information as a test just for stocking levels on a short term basis. We may look at a more sophisticated method after our trial period is completed.

    Any help or pointers would be appreciated.

    Best Regards

    Roth
    Last edited by Roth; 11-05-2009 at 02:41 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: On Value Change Copy Data To Another Sheet

    Welcome to the Board.

    I suspect you're going to need to elaborate a little re: the workflow and processes involved re: Sheet1 - some of us may not be as savvy re: the terminology in use

    Quote Originally Posted by Roth
    The values in sheet 1 are being read in via an OPC server
    So these cells are populated how exactly in laymans terms ? You have formulae or they are updated by an external query or they are populated via code... ?

    The key is we need to understand what is triggering the change in the 11th value... and how the 11th value itself is physically altered (formulae, code etc...).
    It is this which will in determine the appropriate event for capturing said change .... and it is the event that will in turn conduct/invoke your "snapshot".

  3. #3
    Registered User
    Join Date
    10-28-2009
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: On Value Change Copy Data To Another Sheet

    Hi DonkeyOte,

    Thanks for your reply. The 11 cells on sheet1 are linked via DDE to a third party piece of software (RSLinx), the OPC Server. This software is directly linked to a machine where live values populate the cells as shown on the attached workbook.

    The cell named 'Trigger' can be a 0 or 1. When this value goes to 1 we want to append the other ten cell values into a new row on sheet2.

    Hope this explians a little more what we are trying to do, again any help would be appreciated.

    Regards
    Roth
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: On Value Change Copy Data To Another Sheet

    Regards the trigger.. you say when it goes from 0 to 1 ... and thereafter ? ie presumably only if the value drops below 1 and back again would you wish to snapshot ?

  5. #5
    Registered User
    Join Date
    10-28-2009
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: On Value Change Copy Data To Another Sheet

    Hi DonkeyOte,

    Thats correct only when the value is when should the info be copied. This value will go back to zero and then to 1 when the next batch is complete some hours later.

    Regards
    Roth

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: On Value Change Copy Data To Another Sheet

    Well unfortunately DDE updates won't function for me (obviously) but I what I would say is that given the >=1 trigger you could think of using a Static variable in your Worksheet_Calculate event - this will persist during the Excel "session" - this Static variable can (in effect) hold the value of the Trigger prior to current calculation and compare to current value as and when calculation is invoked... when the current Trigger value <> Static / Prior value AND the current trigger value >= 1 then (and only then) would you conduct the snapshot.

    Private Sub Worksheet_Calculate()
    Static boolPrior As Boolean, boolCurrent As Boolean
    boolCurrent = Range("B21") >= 1
    If boolCurrent = boolPrior Then Exit Sub Else boolPrior = boolCurrent
    On Error GoTo ExitPoint
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    If boolCurrent Then
        Range("B1,B3,B5,B7,B9,B11,B13,B15,B17,B19").Copy
        With Sheets("Sheet1")
            .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 10).PasteSpecial xlPasteValues, Transpose:=True
            .Cells(.Rows.Count, "A").End(xlUp).End(xlToRight).Offset(, 1).Value = Now
        End With
        Application.CutCopyMode = False
    End If
    ExitPoint:
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    End Sub
    hopefully that gives pointers if nothing else...

    (and to clarify DDE updates don't invoke the standard Change event... only the Calculate event (like other "standard" formulae))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1