Excel Question- Consolidation of two WBs

Nauas

New Member
Joined
Apr 26, 2016
Messages
31
Office Version
  1. 365
Hi All,
Appreciate if you can please help me resolving following issue I am facing.
I have set of two work books with data
Work Book 1:
HOICITIKOISCOMITELSOFTYBRWAMA
Fixed Assets1245554545
Current Assets3455555
Long term Liabilities4515511
Short term liabilities5555555
Equity5555555

<colgroup><col><col span="7"></colgroup><tbody>
</tbody>

Work Book2:
YBRWHOIOISCOALVIROMITELSOFTCITIKAMA
Sales451451055245
COST53585545
Margin14125551
Admin Exp55515555
Profit55515555

<colgroup><col width="64" span="9" style="width:48pt"> </colgroup><tbody>
</tbody>


Above data is for Balance Sheet and P&L of various companies. But column order is usually different (but both work books are having information related to same companies) making it difficult to just copy and pasting the information of same company under each other. So I have to manually first bring them in same order so that I can just copy paste and bring balance sheet and P&L in same order. There might be instances where one or two companies are not present in any set of data(i.e work book)

Is there any way to automate this to avoid one whole day work. For me due to so many business units take a lot of time to manually adjust them.
 
I still need an answer to my question in Post# 9. If you are copying data based on numbers such as 10000, 10001, 10002, etc., what do you do with column B which has no number in the header? Will the header in column B always be:
BU No
ADB
2016
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi mumps the column a and b will remain constant and copied with other data once they are aligned. The objective is to copy data from wb2 under wb1 based alignment of companies as mentioned in above post. Column a and b will require only copy as it is whereas from column c onwards i need to first align the wb 2 based on the company names with wb1z
 
Upvote 0
Try:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim srcSH As Worksheet
    Set srcSH = Workbooks("Workbook2.xlsx").Sheets("Sheet1")
    Dim LastRow As Long
    LastRow = srcSH.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim header As Range
    Dim foundHeader As Range
    srcSH.Range("A3:B" & LastRow).Copy Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    For Each header In Sheets("Sheet1").Range(Cells(1, 3), Cells(1, Cells(1, Columns.Count).End(xlToLeft).Column))
        Set foundHeader = srcSH.Rows(1).Find(Split(header, Chr(10))(0), LookIn:=xlValues, lookat:=xlPart)
        If Not foundHeader Is Nothing Then
            srcSH.Activate
            Range(Cells(3, foundHeader.Column), Cells(LastRow, foundHeader.Column)).Copy Workbooks("Workbook1.xlsm").Sheets("Sheet1").Cells(Rows.Count, header.Column).End(xlUp).Offset(1, 0)
        End If
    Next header
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps,
I really appreciate your help. But it is still coping the first two column. In the above code I changed

srcSH.Range("A3:B" & LastRow).Copy Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)

"B" to name of my last column ( which is "I"). It is indeed copying the whole data from workbook 2 however it is not aligning the data based on the headers of workbook.

As mentioned earlier. The order of columns is different. So basically code should first align and bring the column in same order and then paste the values under workbook 1 from workbook 2.

I am really indebted to you for your all help. But i believe I am very close to resolve this issue.

Please help.

Regards,
Nauman
 
Upvote 0
Although it is copying the information but not aligning the header based on column data.
And before posting the information it is giving a warning error

"Subscript out of range"
 
Upvote 0
Thanks a lot. Let me see. I can not explain how much you have helped me. I was waiting for your reply
 
Upvote 0
Thanks buddy. It is working on your file. Let me do the same for my file also. This is really helpful.
I am really indebted.
 
Upvote 0
Glad to help. :)
 
Last edited:
Upvote 0
by the way your file is perfectly working but same code on my files is not working. I will find out this and update you. Thanks a lot
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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