+ Reply to Thread
Results 1 to 5 of 5

Copy cell upon close

  1. #1
    Forum Contributor
    Join Date
    12-12-2016
    Location
    Lancaster, PA
    MS-Off Ver
    Office 365
    Posts
    156

    Copy cell upon close

    Hi all,

    I have the below VBA code and I'm looking to amend it so that when the end user closes the workbook, it will copy a specific cell and paste it in the next blank spot in a column.

    In this case, I want it to copy cell F4 and paste it in the next blank cell in column B. The VBA code will then add the date that number was entered.

    Bonus points if you're able to make it so that it does NOT copy if the number has not changed!! That would result in a bunch of unnecessary data points (trying to track the date the number changes).

    Here's the code that adds the date to the non-blank cell:

    Please Login or Register  to view this content.
    I've attached a sample workbook. The proof would be to change the number in F4 (yellow), close the workbook, open it, and the next cell will be filled in in Column B. Ideally then, if you don't change the number, save it, close it, open it, it would not have added the next since the number did not change.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    926

    Re: Copy cell upon close

    Have a try with these changes to your macro and add as directed then Save and reOpen your file and test it:

    1) Change your macro in Sheet2's module to:
    Please Login or Register  to view this content.
    2) Add these macros to your ThisWorkbook module:
    Please Login or Register  to view this content.
    3) In a standard module (create it if not present) declare these variables:
    Please Login or Register  to view this content.
    Last edited by rollis13; 02-07-2023 at 06:08 PM.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,975

    Re: Copy cell upon close

    Approach it the other way - when F4 changes, store the changed value and the date in the first empty row of B and C

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Forum Contributor
    Join Date
    12-12-2016
    Location
    Lancaster, PA
    MS-Off Ver
    Office 365
    Posts
    156

    Re: Copy cell upon close

    Thanks for the help!!!

  5. #5
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    926

    Re: Copy cell upon close

    Thanks for the positive feedback, glad we were able to help.

+ 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. Copy from first workbook, close open new workbook paste close
    By johncarr1952 in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-04-2021, 08:50 AM
  2. [SOLVED] Issue with Open, copy, close Macro - when trying to close workbook Clipboard error
    By seanpcorbett1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2016, 05:14 PM
  3. Save copy as, open copy, alter copy, save copy and close copy
    By tradinup2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-03-2013, 04:42 PM
  4. Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file
    By Langchop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 05:09 AM
  5. Close other workbook after Copy/Paste?
    By proepert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2010, 01:59 AM
  6. Help, I want to copy comments from close workbook
    By HuggyBear in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-10-2005, 06:32 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