Results 1 to 2 of 2

using data in ws1, append data in ws2 only if data is different, otherwise overwrite

Threaded View

  1. #1
    Registered User
    Join Date
    05-11-2017
    Location
    Jacksonville
    MS-Off Ver
    2003
    Posts
    1

    using data in ws1, append data in ws2 only if data is different, otherwise overwrite

    I was hoping someone might be able to help me out with this. I have included the code that I am currently working with. This allows me to transfer a range of data from ws1(Current Performance) to ws2(Past Monthly Performance) and it appends to the next blank row; however, I would like for it to overwrite the existing data based on a condition otherwise it should append it to the next blank row.

    For example, C3 on ws1 shows May 2017. If ws2 has a section that shows May 2017, then I need that range overwritten; otherwise, the new data should append to the existing data.

    Any assistance would be greatly appreciated.

    Sub CopyAllData()
       'update these Const values for Worksheet 1
    
       Const ws1Name = "Current Performance"
       Const firstRowToCopy = 3
       Const alwaysUsedCol = "C"
       Const firstColToCopy = "C"
       Const lastColToCopy = "I"
    
       Const ws2Name = "Past Monthly Performance"
       
       'end of user definable Const values
       
       Dim ws1 As Worksheet
       Dim ws1LastRow As Long
       Dim ws1CopyRange As Range
       Dim ws2 As Worksheet
       Dim ws2NextRow As Long
    
       Set ws1 = Worksheets(ws1Name)
       Set ws2 = Worksheets(ws2Name)
       ws1LastRow = ws1.Range(alwaysUsedCol & Rows.Count).End(xlUp).Row
       If ws1LastRow < firstRowToCopy Then
         ws1LastRow = firstRowToCopy
       End If
       
       Set ws1CopyRange = ws1.Range(firstColToCopy & firstRowToCopy & _
        ":" & lastColToCopy & ws1LastRow)
       ws2NextRow = ws2.Range(alwaysUsedCol & Rows.Count).End(xlUp).Row + 2
       ws1CopyRange.Copy
          'copy all
       ws2.Range(firstColToCopy & ws2NextRow).PasteSpecial Paste:=xlAll
       Application.CutCopyMode = False
       'all done
       Set ws1CopyRange = Nothing
       Set ws1 = Nothing
       Set ws2 = Nothing
    
    End Sub
    Last edited by anoubis450; 05-12-2017 at 11:11 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Overwrite or append data
    By BRISBANEBOB in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-10-2016, 07:30 PM
  2. [SOLVED] Attemting to take a column of data and append it to multiple rows of data on another sheet
    By JamesJohnson31 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-17-2016, 10:34 AM
  3. MACRO to split new data into multiple tabs but not overwrite existing data
    By amo899115 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-11-2016, 01:42 PM
  4. [SOLVED] append data only if date is different, otherwise overwrite
    By roothog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2015, 05:06 PM
  5. Deleted
    By MaxStrong in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2015, 01:50 AM
  6. [SOLVED] Userform: Retrieve data from excel sheet and overwrite with new data in the same rows
    By Pbawal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2014, 11:49 AM
  7. Split data from Master Sheet to existing worksheets and overwrite data
    By vmwest in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-21-2013, 05:36 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