+ Reply to Thread
Results 1 to 24 of 24

Macro to compare columns and copy rows.

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    11-29-2022
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    435

    Re: Macro to compare columns and copy rows.

    Option Explicit
    
    Sub DoThings()
    
        Dim wsN As Worksheet, wsO As Worksheet
        Dim lrow As Integer, nrow As Integer, i As Integer
        Dim str As String, str2 As String
        Dim fndrng As Range
        
        Set wsN = ThisWorkbook.Sheets("NEW")
        Set wsO = ThisWorkbook.Sheets("OLD")
        
        lrow = wsN.Range("A:A").Find(what:="*", searchdirection:=xlPrevious).Row
        nrow = wsO.Range("A:A").Find(what:="*", searchdirection:=xlPrevious).Row + 1
        
        i = 2
        
        Do While i <= lrow
            Set fndrng = wsO.Range("A:A").Find(what:=wsN.Cells(i, 1))
            str = "A" & i & ":F" & i
            
            If fndrng Is Nothing Then
                str2 = "A" & nrow
                nrow = nrow + 1
                
            Else
                str2 = "A" & fndrng.Row
                
            End If
                
            wsN.Range(str).Copy
            wsO.Range(str2).PasteSpecial xlPasteValuesAndNumberFormats
            Application.CutCopyMode = False
            
            'Enable the two rows below if you want to delete the row from New after it has been
            'processed. Remove the ' to un-comment. Also, if you enable them, delete the row below
            'them.
            
    '        wsN.Rows(i).Delete
    '        lrow = lrow - 1
    
            i = i + 1   'Delete this if you enable the two commands above
            
        Loop
    
    End Sub

  2. #2
    Registered User
    Join Date
    09-12-2012
    Location
    Richmond, VA
    MS-Off Ver
    Varies but mostly 365
    Posts
    15

    Re: Macro to compare columns and copy rows.

    Thank you so much, I've matched the specifics up to my main files and running it now. I'm working with only about 3000-3500 rows in the 'New' data tab and it's running on close to 10 minutes now. I added application.screenupdating = false/true to the beginning and end of the sub but it's still running long. Do you think there is anything I can change to make it run faster?

    I've not tried the 30 days portion yet.

    Thanks again !!!

    EDIT: I had to stop the macro after about 15 - 20 minutes, and it appears to have done only 1/2 the data.

    EDIT2: I'm going to try using range.paste instead of .PasteSpecial xlPasteValuesAndNumberFormats on the remaining data and see if there is a duration difference.
    Last edited by JasonMS; 12-16-2022 at 09:57 AM. Reason: Update

+ 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] Macro to compare nominated columns to see if there are entries on the same rows
    By scottiex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-03-2015, 05:31 AM
  2. [SOLVED] Macro to compare nominated columns to see if there are entries on the same rows
    By scottiex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 07:09 PM
  3. [SOLVED] Excel macro, compare two columns from 2 sheets and copy the different rows
    By lagiosman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-10-2013, 11:09 AM
  4. Compare two sheets,copy and paste unique rows based on values in 2 columns
    By ooggiemobile in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2013, 03:58 AM
  5. Need to Compare Two Columns On Different Sheets and Copy Rows with Unique Value
    By triplesechumor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-03-2013, 02:34 AM
  6. [SOLVED] Compare two rows and copy only changes from the columns
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 12:15 AM
  7. Need Macro to Compare Columns and then Reorganize Rows
    By WildSpreadsheets in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-12-2011, 11:03 PM

Tags for this Thread

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