+ Reply to Thread
Results 1 to 3 of 3

Archiving Results

Hybrid View

  1. #1
    Registered User
    Join Date
    04-21-2020
    Location
    UK
    MS-Off Ver
    2010
    Posts
    4

    Archiving Results

    Hi,

    I want to archive results from one spreadsheet to another. I have a macro button to do this (code from a colleague below) and it works when I use it initially. However, if I run the macro again it then fails on the line in bold. I'm not sure why this would be. I have tried stepping through the code and it seems to select the right cell but won't paste.

    Any ideas would be appreciated.

    Many Thanks,
    Zoe

    'set to the current active workbook (the source book)
    Set Test061020 = ActiveWorkbook
    
    'get the active sheetname of the book
    strName = "Archive"
    
    'open a workbook that has same name as the sheet name
    Set TestArchive = Workbooks.Open("Link to archive")
    
     
    'activate the source book
     Test061020.Activate
    
    'clear any thing on clipboard to maximize available memory
    Application.CutCopyMode = False
    
    'copy the range from source book
    Worksheets("Archive").Select
    Worksheets("Archive").Range("A2:I2").Copy
    
    'activate the source book
    TestArchive.Activate
    
    Sheets("Sheet1").Unprotect Password:="Test"
    
     
    Worksheets("Sheet1").Select
    Worksheets("Sheet1").Range("A1").Select 'Selects cell A2 in  archive worksheet
    
            If Worksheets("Sheet1").Range("A1").Offset(1, 0) <> "" Then 'Finds first empty line in archive worksheet
            Worksheets("Sheet1").Range("A1").End(xlDown).Select
            End If
    
        'Steps through the cells of the first empty row and populates the cells with data
        ActiveCell.Offset(1, 0).Select
        ActiveCell.PasteSpecial Paste:=xlPasteValues
       
      Sheets("Sheet1").Protect Password:="Test"
    
    Application.ScreenUpdating = True
    
    'save the target book
    TestArchive.Save
    
    'close the workbook
    TestArchive.Close
    
    'activate the source book again
    Test061020.Activate
    Worksheets("Info").Select
    MsgBox ("Data archived")
    'clear memory
    Set Test061020 = Nothing
    Set TestArchive = Nothing
    
    End Sub
    Last edited by alansidman; 10-08-2020 at 06:08 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,947

    Re: Archiving Results

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    04-21-2020
    Location
    UK
    MS-Off Ver
    2010
    Posts
    4

    Re: Archiving Results

    Apologies Alan. Thank you for sorting that out.

+ 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. Archiving Data
    By kunal.patni in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-15-2017, 06:36 AM
  2. Archiving Data
    By BC TIPPING in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-03-2017, 01:38 AM
  3. VBA for Data Archiving
    By excel1989 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2012, 02:56 PM
  4. Archiving Data
    By skultety in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-03-2010, 10:53 AM
  5. Archiving .XLS Sheets
    By mike in forum Excel General
    Replies: 1
    Last Post: 12-08-2005, 08:45 PM
  6. auto archiving
    By torpido in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2005, 01:58 PM
  7. More Archiving Problems
    By Skankles in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-09-2005, 05:06 PM

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