+ Reply to Thread
Results 1 to 5 of 5

Copy & Paste values on exiting Worksheet

  1. #1
    Forum Contributor
    Join Date
    11-20-2009
    Location
    Melbourne
    MS-Off Ver
    Excel 365
    Posts
    263

    Copy & Paste values on exiting Worksheet

    Hi. I have a worksheet where a formula will populate a cell (eg: L4) when another cell (A4) has been updated.
    When I press exit/close the spreadsheet, I would like to have VBA that copies cells L4:L27 and
    pastes as values prior to closing. Could someone please show me the code to do this. Thank you so much for
    the help offered.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Copy & Paste values on exiting Worksheet

    Paste them where?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    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,895

    Re: Copy & Paste values on exiting Worksheet

    Assuming you were to paste them to M4:M27, the following code would work
    Please Login or Register  to view this content.
    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

  4. #4
    Forum Contributor
    Join Date
    11-20-2009
    Location
    Melbourne
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: Copy & Paste values on exiting Worksheet

    Hi.

    I have added code as shown and I get a 'Run-time error '13':
    Type mismatch

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Copy & Paste values on exiting Worksheet

    Hi, coach.32,

    if you want the action to take place once you deactivate the sheet for the action place this code behind the sheet (right-click on worksheet tab, choose View Code, code goes into the code window):
    Please Login or Register  to view this content.
    This code will only get fired once you are one the sheet and activate another one in the workbook.

    If you want the ation to fire when you exit the workbook the code needs to be placed in ThisWorkbook:
    Please Login or Register  to view this content.
    This code will always save the workbook as well which you should take into consideration. You might also take action in the Workbook_BeforeSave-event.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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] Automatically copy and paste (or update) cell values to another worksheet using VBA code
    By jjin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-21-2013, 04:56 AM
  2. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  3. Copy and Paste (Same worksheet) based on cell values
    By muckem333 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2011, 04:43 PM
  4. Macro to Copy and Paste Values to another Worksheet
    By thillis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2010, 03:13 PM
  5. Copy and paste unique values to another worksheet
    By gsrai31 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-28-2009, 11:44 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