Results 1 to 5 of 5

Copy cell upon close

Threaded View

  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:

    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error GoTo ws_exit:
        Application.EnableEvents = False
        If Not Intersect(Target, Me.Range("B1:B100")) Is Nothing Then
            With Target
                If .Offset(0, -1) <> "" Then GoTo ws_exit
                If .Value <> "" Then
                    .Offset(0, 1).Value = Format(Now, "m/d/yyyy")
                End If
            End With
        End If
    ws_exit:
        Application.EnableEvents = True
    End Sub
    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

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