+ Reply to Thread
Results 1 to 12 of 12

dde data copied from sheet1 to sheet2

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2009
    Location
    Pensacola FL
    MS-Off Ver
    Excel 2003
    Posts
    7

    dde data copied from sheet1 to sheet2

    I am enlcosing a file that I partially acquired (the macro portion) and I am trying to add to that.

    The workbook has a dde link in sheet 1, the macro will write the data to sheet2 at set times. I am creating a report of the data in sheet 2 in sheet3. at this point it is very rudimentary. I need some assistance to clean up the macro and the post of the dat in sheet2. I have created a detailed (probably over detailed) explanantion in sheet 1 in a text box.

    Thanks for any and all assistance given as my programming/excel skills are very limited.

    Thanks
    cb
    Attached Files Attached Files

  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 data copied from sheet1 to sheet2

    Hello Chuckb74,

    Welcome to the Forum!

    I revised your macro The_Sub. It nows checks if cell "A1" on "Sheet2" has any data. If not, this is first cell the data is pasted into. Otherwise it will use the next empty cell in column "A".
    Sub The_Sub()
    'MsgBox ""
    '
    ' your code here
    '
    Dim LastRow As Long
    
      If Time < TimeValue("09:30:00 AM") Then Exit Sub
      If Time > TimeValue("03:30:00 PM") Then Exit Sub
    
      With Worksheets("sheet1")
       '.Range("a1:d1").Copy
        .Range("A1").Copy
    
       'Start in cell A1
        With Worksheets("Sheet2")
          LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
          If LastRow = 1 And .Cells(1, "A") = "" Then
             .Cells(1, "A").PasteSpecial Paste:=xlPasteValues
          Else
             .Cells(LastRow + 1, "A").PasteSpecial Paste:=xlPasteValues
          End If
        End With
        
      End With
      
      Application.CutCopyMode = False
    
      StartTimer
    
    End Sub
    Last edited by Leith Ross; 08-28-2009 at 04:21 PM.
    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-27-2009
    Location
    Pensacola FL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: dde data copied from sheet1 to sheet2

    Thanks so much for taking the time out to fix that.

    Will that also fix the overwriting of the entire line instead of just the cell or can that be stopped?

    Thanks
    cb

  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 data copied from sheet1 to sheet2

    Hello CB,

    It only copies cell "A1" from "Sheet1" over to "Sheet2". The headers in column "B" on are safe.

  5. #5
    Registered User
    Join Date
    08-27-2009
    Location
    Pensacola FL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: dde data copied from sheet1 to sheet2

    Leith,
    Thanks so much for that. How difficult would it be to write a date/time stamp in the corresponding cell in column b on the data that is being written into sheet2? That would get rid of my labels and it would allow me to double check the time the data is being written into the file.


    Thanks Very much again.

    Sincerely,
    cb

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: dde data copied from sheet1 to sheet2

    Maybe like this:
    Sub The_Sub()
        '
        ' your code here
        '
        Dim LastRow     As Long
    
        If Time < #9:30:00 AM# Or Time > #3:30:00 PM# Then Exit Sub
    
        With Worksheets("Sheet2")
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
            If LastRow <> 1 Or .Cells(1, "A") <> Empty Then LastRow = LastRow + 1
            .Cells(LastRow, "A").Resize(, 2).Value = Array(Worksheets("Sheet1").Range("A1").Value, Now)
        End With
    
        StartTimer
    End Sub
    Last edited by shg; 08-30-2009 at 08:02 PM.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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