CaliburBlade138
New Member
- Joined
- Apr 18, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- 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!
OLD~~~>
NEW ~~~>
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
NEW ~~~>