Results 1 to 7 of 7

Macro to copy/paste values to new row OR overwrite existing row

Threaded View

  1. #1
    Registered User
    Join Date
    07-29-2021
    Location
    Charleston, SC
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Question Macro to copy/paste values to new row OR overwrite existing row

    Just signed up for this and having trouble finding a solution to the challenge I have at hand. I'm hoping someone can help, and I apologize if there's already been a solution posted, but I wasn't able to find it, so here goes!

    I have a weekly report that will be used to collect data for an asset, and I have built a simple macro to copy & paste the values of that data to a new row on a separate sheet. The purpose is to keep a log of weekly stats so we can identify trends. The macro is working as intended, but I want to improve it to be able to account for a certain element of human error.

    It is reasonable to assume that the people filling out the weekly report will at one point or another (or maybe more often than that) click the "Finalize Report" button which cues the macro to publish the data to a new row, then shortly thereafter realize that they need to correct some data and "re-finalize", thus re-publishing the data to a new row. This would result in multiple rows of data for the same date. The sheet where this is happening is password protected by design so that it can't be altered. I would like to redesign the macro to paste the data to a new row ONLY if the value in column A (the date of the report) is unique, and if the value in column A already exists in the list of data, then overwrite that row with the new data.

    This seems like something that's possible, but I'm fairly new to macros, so I could use some help!

    Here's the macro code as-is, which simply copies and pastes the values to a new row:

    Sub FinalizeReport()
    '
    ' FinalizeReport Macro
    '
    
    '
        Sheets("Cumulative Stats").Select
        ActiveSheet.Unprotect Password:="29401"
        Range("A2:AD2").Select
        Selection.Copy
        Range("A" & Rows.Count).End(xlUp).Offset(1).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Cumulative Stats").Select
        Application.CutCopyMode = False
        ActiveSheet.Protect Password:="29401"
        Sheets("Weekly Report").Select
    End Sub
    Last edited by alansidman; 07-29-2021 at 07:18 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy existing (hidden) worksheet and replace/overwrite existing worksheet in same workbook
    By Funkymonkey0073 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-11-2020, 08:44 AM
  2. Macro to copy and paste without overwriting existing data
    By jmack36 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-18-2016, 07:49 AM
  3. Deleted
    By MaxStrong in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2015, 01:50 AM
  4. Copy paste data without overwritting existing values
    By GusAlmeida in forum Excel General
    Replies: 2
    Last Post: 01-15-2015, 02:19 AM
  5. Replies: 11
    Last Post: 11-04-2013, 04:32 PM
  6. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  7. [SOLVED] Change existing MACRO to only copy/paste Values
    By williampdx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2012, 08:07 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