+ Reply to Thread
Results 1 to 4 of 4

trying to amend this code to auto save new data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-28-2016
    Location
    Seattle, washington
    MS-Off Ver
    Microsoft 365
    Posts
    347

    trying to amend this code to auto save new data

    Hello, I am using this code to transfer data from one sheet to another. I need to be able to add new data to the Complete tab on the next line down, and keep the existing data. currently it clears the old data when new data from the call in log is transferred. Thanks for any help provided.

    Sub cpyToComplete() 
         
         
        Sheets("Complete").Range("A2:I").Value = Sheets("FXF CALL IN LOG").Range("A3:I").Value 
        Sheets("Complete").Range("J1").Value = Sheets("FXF CALL IN LOG").Range("I1").Value 
         
        Sheets("FXF CALL IN LOG").Range("A3:I").Value = "" 
         
         
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,115

    Re: trying to amend this code to auto save new data

    Hello Steve,

    It appears that you are transferring a complete, hard-coded data block to the second sheet (always to the same area: "A2:I") which is why the older data is being overwritten. You may have to try a different tack, such as:-


    Sub CopyData()
    
        Dim lrow As Long
    
    Application.ScreenUpdating = False
    
    lrow = Range("A" & Rows.Count).End(xlUp).Row
    
    If lrow > 2 Then
    Sheet1.Range("A3:I" & lrow).Copy
    Sheet2.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
    Sheet1.Range("A3:I" & lrow).ClearContents
    End If
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub
    where sheet1 (Call in Log) is the source sheet and sheet2 is the destination sheet (Complete).

    This will add the transferred data to the bottom of the existing data in sheet2.

    (You could do the same for the second line of code in your opening post and add it in to the above code).

    I hope that this works for you.

    Cheerio,
    vcoolio.

  3. #3
    Forum Contributor
    Join Date
    09-28-2016
    Location
    Seattle, washington
    MS-Off Ver
    Microsoft 365
    Posts
    347

    Re: trying to amend this code to auto save new data

    thanks Vcoolio, appreciate your time looking at it. I will test this one in a little bit. I got it working with this code -

    Sub cpyToComplete()
         
    Application.ScreenUpdating = False
    Dim CopySheet As Worksheet
    Dim PasteSheet As Worksheet
    
    Set CopySheet = Worksheets("FXF CALL IN LOG")
    Set PasteSheet = Worksheets("Complete")
    
    PasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(2, 0).Value = Sheets("FXF CALL IN LOG").Range("I1").Value
    CopySheet.Range("A2:I15").Copy
    PasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    
    Sheets("Complete").Select
    Sheets("Complete").Range("J1").Select
    Sheets("FXF CALL IN LOG").Select
    Sheets("FXF CALL IN LOG").Range("J4").Select
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,115

    Re: trying to amend this code to auto save new data

    No worries Steve. Glad that I was able to help in some way.

    Cheerio,
    vcoolio.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Amend code to check cell A2 has data in before running
    By robertguy in forum Excel General
    Replies: 2
    Last Post: 12-11-2016, 09:13 AM
  2. Replies: 1
    Last Post: 05-27-2016, 07:45 PM
  3. Replies: 5
    Last Post: 10-22-2015, 01:30 PM
  4. Amend VBA Code to Clear Data
    By Renleff in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 09-26-2014, 04:15 PM
  5. Amend default Save As directory
    By rossp1977 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-15-2014, 10:34 AM
  6. Code to Auto-Save
    By KLahvic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2009, 09:04 AM
  7. Amend Code - Save file with cell as name from different sheet.
    By Sirishgreen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2007, 05:32 AM

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