Copy data from a cell that reads live values from PLC via DDE connection.

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    That line must be outside all routines and at the top of the worksheet code module.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    I think the problem is that Dim vOldVal wont fire with Worksheet_Calculate. Seems that it fires with Worksheet_Changeonly. It is outside all Routines. Its at the top. Doesn't do the trick.
    I [ATTACH=CONFIG]59317[/ATTACH]added a screenshot.

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    vOldVal doesn't fire - it's a variable that stores the last value of A5 so that the code only runs when that changes. If the code isn't running, then that value isn't changing.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    Well i just checked it. All cells are changing. The cell from the DDE is updating to TRUE. Obviously the cell=TRUE is updating and the target cell changes from "150" to "-100". So obviously there is a conflict with oldval. Maybe we have to enable events? What do you think?

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    Events should already be enabled unless you have disabled them somehow. Try adding:

    Code
    Msgbox "Calculate"


    as the first line of the Calculate event code to see if it's being triggered.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    Well it appears as well. Don't understand where the problem is really! Sorry for bothering you.

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    I moved the CopyValues macro after the first EndIf (See pic attached). It works like before, it makes several copies. But why CopyValues wont fire in the loop of the second if as you wrote it at first?

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    Please clarify exactly which formulas and values are where.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    [ATTACH=CONFIG]59320[/ATTACH]


    As you can see A1 reads from DDE and it is named Input. A3 reads TRUE/FALSE from DDE. A5=A3 and A7=if(A5=FALSE,"100","-100")
    C is output and D is Time

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    Then try changing the code to:

    Code
    Dim vOldVal 
    Private Sub Worksheet_Calculate() 
        If Range("A7").Value = -100 Then 
            If Range("A1").Value <> vOldVal Then 
                vOldVal = Range("A1").Value 
                CopyValues 
            End If 
        End If 
    End Sub

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    You my friend are the BEST! WOW! It is working. I really appreciate your time. Is there any Donate button for the forum or you? I have a couple of things to work out (like auto saving at the end of the date, start new file the next day, graphs, printing etc...) but I think its enough. I cant ask for more. Thanks again.

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    If you feel so inclined there is information in my profile, but there is absolutely no obligation!

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    It wont be so fast as my answers as I am not good at online money transactions, but I will manage to do it. Thanks again and sorry for my English. I am Greek, so its not easy for me. Have a nice day and we ll be in touch.

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    Your English is a lot better than my Greek, believe me! :)

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    I do believe you. Greek people cant talk Greek properly. I can only imagine about other people. Tough language. Its a bless I didn't had to learn it.

  • Re: Copy data from a cell that reads live values from PLC via DDE connection.


    HI ,
    I have tried this method , but for some reason it gives me error , can some one help me .
    I have DDE link on cell "B3" and it gets updated on Cell "D2" via this method once, but, Next time the same row gets updated deleting the previous value.


    Can some one explain me what is actually meant by this
    ThisWorkbook.Names("Output2").RefersTo = Worksheets("Sheet1").Range("Output2").Offset(1, 0)


    Also how should
    DDE link look like , i have this "RSLINX|ex1!'Input,L1,C1"


    help me understand it

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!