+ Reply to Thread
Results 1 to 11 of 11

DDE-link problem

Hybrid View

nyrn2k DDE-link problem 08-22-2009, 01:57 PM
Leith Ross Re: DDE-link problem 08-22-2009, 07:12 PM
nyrn2k Re: DDE-link problem 08-23-2009, 03:47 PM
Leith Ross Re: DDE-link problem 08-23-2009, 05:39 PM
nyrn2k Re: DDE-link problem 08-24-2009, 01:35 AM
nyrn2k Re: DDE-link problem 09-14-2009, 07:06 AM
  1. #1
    Registered User
    Join Date
    08-22-2009
    Location
    stockholm
    MS-Off Ver
    Excel 2007
    Posts
    8

    DDE-link problem

    hi all
    i would like some help with DDE-linking.
    i want to link my stock portfolio to a spreadsheet to make various calculations on historic performance.
    my problem is that it is the same cell thats get updated whenever a change occurs, so that there is no history.

    let's say i put the DDE-link in cell A1, i would like B1 to be filled with that value
    and then when the value changes i would like B2 to be filled with the new value
    and the next time B3, and so on.

    can anyone help me?

    thanks
    nyrn2k

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: DDE-link problem

    Hello nyrn2k,

    Because the link will only update the cell, you need a macro that will trigger when cell "A1" changes to create the history.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      On Error GoTo ExitOut
      Application.EnableEvents = False
      
        If Not IsEmpty(Target) And Target.Address = "$A$1" Then
          If IsEmpty(Range("B1")) Then
             Range("B1") = Target
          Else
             Range("B1").End(xlDown).Offset(1, 0) = Target
          End If
        End If
      
    ExitOut:
      Application.EnableEvents = True
      Err.Clear
      
    End Sub
    How to Save a Worksheet Event Macro
    1. Copy the macro using CTRL+C keys.
    2. Open your Workbook and Right Click on the Worksheet's Name Tab for the Worksheet the macro will run on.
    3. Left Click on View Code in the pop up menu.
    4. Paste the macro code using CTRL+V
    5. Make any custom changes to the macro if needed at this time.
    6. Save the macro in your Workbook using CTRL+S
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    08-22-2009
    Location
    stockholm
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: DDE-link problem

    thanks

    i followed your instructions but i could only get it to work once when A1 was empty and i filled it with a number.
    then when i changed A1 nothing happened...
    do i need to do something else aswell, or am i doing something wrong?

    i have another question;
    how do i make a cell show the last value in a row?

    thanks for your help

    /nyrn2k

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: DDE-link problem

    Hello nyrn2k,

    That was my error, not yours. I rewrote the code and this works correctly. Delete the previous macro and replace it with this version.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      On Error GoTo ExitOut
      Application.EnableEvents = False
      
        If Not IsEmpty(Target) And Target.Address = "$A$1" Then
          If IsEmpty(Range("B1")) Then
             Range("B1") = Target
          Else
             Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = Target
          End If
        End If
      
    ExitOut:
      Application.EnableEvents = True
      Err.Clear
      
    End Sub

  5. #5
    Registered User
    Join Date
    08-22-2009
    Location
    stockholm
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: DDE-link problem

    thank you

    it worked beautifully, exactly what i wanted, when i changed the value of A1 manually.
    however, it didn't work when i put a link in A1, then the change didn't trigger...

    and also, the new question again:
    how do i make a cell show the last value in a row?

    /nyrn2k
    Last edited by nyrn2k; 08-24-2009 at 01:45 AM.

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

    Re: DDE-link problem

    A DDE-link will not invoke the Change event, you will need to use the Calculate event but that in itself is open to error (ie the Calculate event can be invoked by all manner of events not simply a DDE update - trapping the DDE update is not as trivial as it first seems)... if you run a search on the forum on DDE you should find a lot of examples - possible workarounds.

    see: http://www.excelforum.com/excel-work...matically.html

    In the above I make mention of a couple of ideas mentioned to me by Colin Legg (MS Excel MVP) which might prove useful to you...
    Last edited by DonkeyOte; 08-24-2009 at 02:25 AM.

  7. #7
    Registered User
    Join Date
    08-22-2009
    Location
    stockholm
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: DDE-link problem

    thanks for all your help!

    how would i make excel do this for multiple different stocks, but only check/update latest price once every ten minutes?
    Last edited by nyrn2k; 09-14-2009 at 08:58 AM.

+ 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