Is there a way to update my code to compare rows differently?

CaliburBlade138

New Member
Joined
Apr 18, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello all!

So a quick run down here, I have two workbooks that need to be compared OLD.xlsx and NEW.xlsx, now the OLD will have formatting, comments, etc... The NEW is a data dump by the system that will be clear of formatting, comments, etc... Completely fresh. I need to compare the OLD to the NEW workbook, if the row contains all the same strings or data from the OLD, copy and paste that entire row overwriting it including formatting, comments, etc... to the NEW workbook. I have coded it to work some what, but it compares line by line and row by row and if there is new data in the NEW workbook, it completely messes up the process. Plus I haven't figured out how to copy and paste the data so thus it just highlights =/ Here is my code. Any help would be great!

VBA Code:
Const SHT_NAME = "Daily"

Dim pathToFile As String
Dim copyFromWorkbook As Workbook
Dim copyToWorkbook As Workbook
Dim copyFromWorksheet As Worksheet
Dim copyToWorksheet As Worksheet
Dim lastRowA As Long
Dim joinRow As String
Dim i As Long

Sub Copy_Workbook()

  With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1
        .Show
        
        pathToFile = .SelectedItems.Item(1)
    End With
    
    If InStr(pathToFile, ".xls") = 0 Then
        Exit Sub
    End If
    
    Set copyFromWorkbook = Workbooks.Open(pathToFile, True, True)
    Set copyFromWorksheet = copyFromWorkbook.Sheets(SHT_NAME)
    
    Set copyToWorkbook = ThisWorkbook
    Set copyToWorksheet = copyToWorkbook.Sheets(SHT_NAME)
    
    lastRowA = copyFromWorksheet.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To lastRowA
        If Trim(copyFromWorksheet.Range("B" & i).Value) <> Trim(copyToWorksheet.Range("B" & i).Value) Then
            copyToWorksheet.Range("B" & i).Interior.Color = vbGreen
            Else
            copyToWorksheet.Range("B" & i).Interior.Color = vbRed
        End If
    Next i
    
    Application.ScreenUpdating = True
    
End Sub
OLD~~~>
old.png


NEW ~~~>
new.png
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,144,522
Messages
5,724,831
Members
422,582
Latest member
Vaibhav Wadhwa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top