Try this:-
Code:
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys]Public Sub MergeWorkbooks()[/FONT]
[FONT=Fixedsys] Dim strWorkbook1 As String[/FONT]
[FONT=Fixedsys] Dim wb1 As Workbook[/FONT]
[FONT=Fixedsys] Dim ws1 As Worksheet[/FONT]
[FONT=Fixedsys] Dim oCell1 As Range[/FONT]
[FONT=Fixedsys] Dim strWorkbook2 As String[/FONT]
[FONT=Fixedsys] Dim wb2 As Workbook[/FONT]
[FONT=Fixedsys] Dim ws2 As Worksheet[/FONT]
[FONT=Fixedsys] Dim oCell2 As Range[/FONT]
[FONT=Fixedsys] Dim iChanged As Long[/FONT]
[FONT=Fixedsys] Dim strMessage As String[/FONT]
[FONT=Fixedsys] strWorkbook1 = Application.GetOpenFilename(FileFilter:="Excel workbooks (*.xl*), *.xl*")[/FONT]
[FONT=Fixedsys] If strWorkbook1 = "False" Then Exit Sub[/FONT]
[FONT=Fixedsys] strWorkbook2 = Application.GetOpenFilename(FileFilter:="Excel workbooks (*.xl*), *.xl*")[/FONT]
[FONT=Fixedsys] If strWorkbook2 = "False" Then Exit Sub[/FONT]
[FONT=Fixedsys] Application.ScreenUpdating = False[/FONT]
[FONT=Fixedsys] Set wb1 = Workbooks.Open(strWorkbook1)[/FONT]
[FONT=Fixedsys] Set ws1 = wb1.Sheets(1)[/FONT]
[FONT=Fixedsys] Set wb2 = Workbooks.Open(strWorkbook2)[/FONT]
[FONT=Fixedsys] Set ws2 = wb2.Sheets(1)[/FONT]
[FONT=Fixedsys] iChanged = 0[/FONT]
[FONT=Fixedsys] For Each oCell1 In ws1.UsedRange[/FONT]
[FONT=Fixedsys] Set oCell2 = ws2.Range(oCell1.Address)[/FONT]
[FONT=Fixedsys] If IsEmpty(oCell2) Then[/FONT]
[FONT=Fixedsys] If Not IsEmpty(oCell1) Then[/FONT]
[FONT=Fixedsys] oCell1.Copy Destination:=oCell2[/FONT]
[FONT=Fixedsys] iChanged = iChanged + 1[/FONT]
[FONT=Fixedsys] End If[/FONT]
[FONT=Fixedsys] End If[/FONT]
[FONT=Fixedsys] Next oCell1[/FONT]
[FONT=Fixedsys] Application.ScreenUpdating = True[/FONT]
[FONT=Fixedsys] strMessage = vbCrLf _[/FONT]
[FONT=Fixedsys] & "Values from " & wb1.Name & " have been overlaid onto " & wb2.Name & "." _[/FONT]
[FONT=Fixedsys] & Space(10) & vbCrLf & vbCrLf _[/FONT]
[FONT=Fixedsys] & "Number of cells updated: " & iChanged _[/FONT]
[FONT=Fixedsys] & Space(10) & vbCrLf & vbCrLf _[/FONT]
[FONT=Fixedsys] & "Please save " & wb2.Name & " if you want to preserve these changes." _[/FONT]
[FONT=Fixedsys] & Space(10)[/FONT]
[FONT=Fixedsys] wb1.Close savechanges:=False[/FONT]
[FONT=Fixedsys] MsgBox strMessage, vbOKOnly + vbExclamation[/FONT]
[FONT=Fixedsys]End Sub[/FONT]
Open a new workbook, paste this code into a new general code module and run it.
It will prompt you to open two workbooks, then it will copy the cells from
workbook1.sheet1 to
workbook2.sheet1 if the cell in
workbook2.sheet1 is empty.
Workbook1 is not changed: all the changes are made to
workbook2 but
workbook2 isn't saved back to disk - you have to do that manually. Any macros in
workbook2 are left untouched.
See if that's any use to you. Shout if you need any changes.