Merging Data From 2 Workbooks

slimano

New Member
Joined
Apr 18, 2011
Messages
13
Hi Andrew,

I have 2 sets of data (100 and 101) for a set of entities (A, B) that i want to merge.
I have written a macro that combines all the data of 101 for A,B into one file (data 101) and also combines all the data of 100 for A,B into another file (data 100).

Now i want to merge the 2 files into a single master file called "combined" in a specific format and save it. Can you please help?

my code so far is as follows:
Code:
Sub tiso()
Dim fn, e, wb As Workbook
Dim LastRow As Long
Dim NextCell As Range
Dim First As Boolean
Dim sAppPath As String, sFileName As String, sDate As String

fn = Application.GetOpenFilename(FileFilter:="Microsoft excel files (*.xls), *.xls", _
                     Title:="Go to Data 100 and Press CTRL A to Select All the Files", MultiSelect:=True)
If Not IsArray(fn) Then Exit Sub
Set wb = Workbooks.Add
'wb.SaveAs Filename:="C:\tiso\compiled & Format(Date, "").xls"

sAppPath = "c:\tiso\"
sDate = Replace(FormatDateTime(Now(), vbShortDate), "/", "-")
sFileName = sAppPath & "Data 100  " & sDate & ".xls"

ActiveWorkbook.SaveAs Filename:= _
sFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

For Each e In fn
    With Workbooks.Open(e)
        With .Sheets(1)
            'LastRow = Range("A65536").End(xlUp).Row
            'Range("B15", Cells(LastRow + 1, "J")).Copy
            Range("a4:b4").Cells.Copy
            wb.Sheets(1).Cells(wb.Sheets(1).Cells.SpecialCells(11).Row + 2, 2).PasteSpecial xlPasteValues
            Range("b15 : h15,b17 : h17").Cells.Copy
            wb.Sheets(1).Cells(wb.Sheets(1).Cells.SpecialCells(11).Row + 2, 2).PasteSpecial xlPasteValues
           ' Range("b17 : h17").Cells.Copy
            'wb.Sheets(1).Cells(wb.Sheets(1).Cells.SpecialCells(11).Row + 1, 2).PasteSpecial xlPasteValues
        End With
        .Close False
    End With
Next

Application.CutCopyMode = False
Set wb = Nothing

fn = Application.GetOpenFilename(FileFilter:="Microsoft excel files (*.xls), *.xls", _
                     Title:="Go to Data 101 and Press CTRL A to Select All the Files", MultiSelect:=True)
If Not IsArray(fn) Then Exit Sub
Set wb = Workbooks.Add
'wb.SaveAs Filename:="C:\tiso\compiled & Format(Date, "").xls"

sAppPath = "c:\tiso\"
sDate = Replace(FormatDateTime(Now(), vbShortDate), "/", "-")
sFileName = sAppPath & "Data 101  " & sDate & ".xls"

ActiveWorkbook.SaveAs Filename:= _
sFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

For Each e In fn
    With Workbooks.Open(e)
        With .Sheets(1)
            'LastRow = Range("A65536").End(xlUp).Row
            'Range("B15", Cells(LastRow + 1, "J")).Copy
            Range("a4:b4").Cells.Copy
            wb.Sheets(1).Cells(wb.Sheets(1).Cells.SpecialCells(11).Row + 2, 2).PasteSpecial xlPasteValues
            Range("b15 : d16").Cells.Copy
            wb.Sheets(1).Cells(wb.Sheets(1).Cells.SpecialCells(11).Row + 2, 2).PasteSpecial xlPasteValues
           ' Range("b17 : h17").Cells.Copy
            'wb.Sheets(1).Cells(wb.Sheets(1).Cells.SpecialCells(11).Row + 1, 2).PasteSpecial xlPasteValues
        End With
        .Close False
    End With
Next

Application.CutCopyMode = False
Set wb = Nothing

End Sub

Data 100
Excel Workbook
BCDEFGH
3Data A******
4*******
5EQUIVALENT( MILLONS)3292668LONG-11638SHORT737897.1LONG
6NET OWN FUNDS(NOFs)7.32LONG-0.03SHORT1.64LONG
7*******
8Data B******
9*******
10EQUIVALENT( MILLONS)3292668LONG-11638SHORT737897.1LONG
11NET OWN FUNDS(NOFs)7.32LONG-0.03SHORT1.64LONG
Sheet1

Data 101
Excel Workbook
BCD
3Data A**
4***
5NOP IN PERCENTAGE%27232600LONG
6AFOP IN PERCENTAGE1.53LONG
7***
8Data B**
9***
10NOP IN PERCENTAGE%27232600LONG
11AFOP IN PERCENTAGE1.53LONG
Sheet1

Combined should look like this:
Excel Workbook
BCDEFGHI
2Data A*******
3********
4EQUIVALENT( MILLONS)4,380,526.71LONG22,732.22LONG496,252.16LONG*
5NET OWN FUNDS(NOFs)******45,001,589.54
6NOP IN PERCENTAGE9.73LONG0.05LONG1.10LONG*
7AFOP IN PERCENTAGE******12.72
8********
9Data B*******
10********
11EQUIVALENT( MILLONS)-16,985,152.40SHORT-464,904.61SHORT96,455.07LONG*
12NET OWN FUNDS(NOFs)******264,186,952.00
13NOP IN PERCENTAGE%-6.43SHORT-0.18SHORT0.04LONG*
14AFOP IN PERCENTAGE******-6.61
Sheet1

Can anyone please assist? Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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
Back
Top