Hello
I no know if this code fits my project. I got this code from the internet . I want matching column B between two files . the file1 should match with file 2. if there is different the data in file 2 then should replace new data in file 1 the range is from A:E and the headers in row1
I got error object variable block in this line
any suggestion guy to do that
I no know if this code fits my project. I got this code from the internet . I want matching column B between two files . the file1 should match with file 2. if there is different the data in file 2 then should replace new data in file 1 the range is from A:E and the headers in row1
I got error object variable block in this line
VBA Code:
m = Application.Match(rw.Cells(1).Value, wsDest.Columns("B"), 0)
VBA Code:
Sub Button2_Click()
Dim OpenFileName As String
Dim wb As Workbook
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim m, rw As Range
OpenFileName = Application.GetOpenFilename 'Select and Open workbook
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName, ReadOnly:=True)
Set wsCopy = wb.Worksheets("Data") 'for example
For Each rw In wsCopy.Range("A2:E" & wsCopy.Cells(Rows.Count, "A").End(xlUp).Row).Rows
'matching row based on Id ?
m = Application.Match(rw.Cells(1).Value, wsDest.Columns("B"), 0)
'if we didn't get a match then we add a new row
If IsError(m) Then m = wsDest.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row 'new row
rw.Copy wsDest.Cells(m, "A") 'copy row
Next rw
wb.Close False 'no save
End Sub