I have two workbooks. The first workbook(69 worksheets)has old data and the second workbook has new data for some of the worksheets(42 worksheets) of Workbook1. Only the first three columns needs updation in the first workbook. SO I want to create a macro running a loop though Workbook1 from sheet 1 to all the worksheets, finding the same worksheet name in Workbook 2 and copying first three columns and updating them in Workbook1. Can somebody please help me with it.I have created the following code , obviously not working!!
Sub Macro1()
Dim i As Integer
Dim x As Integer
Dim wb2 As Excel.Workbook
Dim rngToCopy As Range
Dim rngToPaste As Range
Set wb2 = Workbooks.Open("D:\Sediment extraction\Analysis\updatedextractedresults_45.xls")
j = ThisWorkbook.Worksheets.Count
k = wb2.Worksheets.Count
For i = 1 To j
For x = 1 To k
If ThisWorkbook.Sheets(i).Name = wb2.Sheets(x).Name Then
wb2.Sheets(x).Activate
Set rngToCopy = ThisWorkbook.Sheets(x).Range("A1",ThisWorkbook.Sheets(x).Range("A65536").End(xlUp)).Resize(, 3)
'With rngToCopy
Set rngToPaste = ThisWorkbook.Sheets(i).Range("A1").Resize(.Rows.Count, .Columns.Count)
End With
'rngToPaste.Value = rngToCopy.Value
End If
Next x
Next i
End Sub