+ Reply to Thread
Results 1 to 7 of 7

VBA If Then Else. Find matches then copy paste to overwrite data

  1. #1
    Registered User
    Join Date
    01-02-2020
    Location
    LA, Cali
    MS-Off Ver
    365
    Posts
    9

    VBA If Then Else. Find matches then copy paste to overwrite data

    Hello everyone!

    I have two spreadsheets in a workbooks.
    Sheets.LiveData contains the most update to date information based on a ProjectID (status, dates..)
    Sheets.toUpdate contains the ProjectID and applicable columns.

    I would like to look at LiveData.ProjectID and for each row, find the match in toUpdate.ProjectID range.
    If a match is found, I want LiveData.A:E data for that matched row to be pasted over the matched row of toUpdate A:E, overwriting the existing data for that matched row.
    If a match is not found, then I want to copy the unmatched row from LiveData.A:E and paste to the next available row in toUpdate.A:E.
    Attached Files Attached Files
    Last edited by nordxnortheast; 08-18-2020 at 07:46 AM.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: VBA If Then Else. Find matches then copy paste to overwrite data

    I would expect that the ever-so-popular, and heavily used mixing of MATCH() and VLOOKUP() could be very helpful here. and you may not even need any code. it looks like the copy over might be just a relative reference issue written into the formulas I just mentioned. have you ever done something like that? that is not a code routine.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,560

    Re: VBA If Then Else. Find matches then copy paste to overwrite data

    Try
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this demonstration !


    According to the attachment as a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
        
    Dim R&, VL&
            
    Application.ScreenUpdating False
        With Sheet4
    .[A1].CurrentRegion
            R 
    = .Rows.Count
            V 
    = .Columns(2).Value2
        End With
        With Sheet3
    .[A1].CurrentRegion.Rows
                V 
    Application.Match(.Columns(1).Value2V0)
            For 
    2 To .Count
                
    If IsError(V(L1)) Then R 1: .Item(L).Copy Sheet4.Cells(R2_
                                    
    Else .Item(L).Columns("B:E").Copy Sheet4.Cells(V(L1), 3)
            
    Next
        End With
            Application
    .ScreenUpdating True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-18-2020 at 05:47 AM. Reason: optimization …

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,262

    Re: VBA If Then Else. Find matches then copy paste to overwrite data

    Another Option...
    Please Login or Register  to view this content.
    Last edited by sintek; 08-18-2020 at 06:22 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    01-02-2020
    Location
    LA, Cali
    MS-Off Ver
    365
    Posts
    9

    Re: VBA If Then Else. Find matches then copy paste to overwrite data

    Each of these solutions worked! Thank you for the support!

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,262

    Re: VBA If Then Else. Find matches then copy paste to overwrite data

    Glad I could contribute...Tx for rep +

+ 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] Copy & paste of the data if matches
    By MoldyBread in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-23-2020, 08:13 AM
  2. [SOLVED] Copy master wb/ws to new wb/ws to overwrite data only if column a info matches both
    By paula.mccall in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-26-2019, 03:47 PM
  3. Copy from one sheet and paste to another - overwrite all data
    By csaavs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2017, 04:02 AM
  4. Find matches, copy and paste adjacent cell
    By amein in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-23-2016, 11:21 AM
  5. Deleted
    By MaxStrong in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2015, 01:50 AM
  6. Copy and paste to new worksheet but overwrite if data already exists.
    By digimon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2015, 11:17 PM
  7. [SOLVED] Copy/Paste from a Filtered Range and Insert copied data NOT overwrite
    By Simon.Ward in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-12-2013, 11:14 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