Create a data table from Multiple Tabs

Grimm127

Board Regular
Joined
Aug 17, 2011
Messages
132
Hi Guru's

I have a question. I have 10 Tabs. Each with 2,387 Rows with Columns A:BW. I want to merge all those tabs into One separate tab. I only need to extract Columns A:F; I-U;W-AH and all the rows. How do I set this up?

I would guess it would be something like

For each pnlTAB in Worksheets (Array ("Tab1","Tab",..ect)
go to tab 1 copy rows 1 thru 2,387 and go to Tab_Merge and paste at row 1
go to tab 2 copy rows 1 thru 2,387 and go to Tab_Merge and paste row 2,388
go to tab 3 copy rows 1 thru 2,387 and go to Tab_Merge and paste row 4,775

Something along those lines. Any help would be great as I am sort of stuck.....

Thanks in Advance
 
Hello Grimm127,

We can use a sheet name range to exclude the sheets that you don't want included in the data transfer. This method would be a tidier way of doing this.

Hence, open a new sheet and name it say Sheet List. In cell A1 of this new sheet, place the heading ShList. Now, from A2 down, place the names of all the sheets that you wish to exclude starting with the name of your main sheet (Master) in A2 and then Sheet List in A3 with the other sheets following on from there.

Next, high-light (select) all the sheet names that you have in the list, including the heading (ShList). Go to the Formulas tab and select Define Name. A little dialogue box will appear. Check that the details are correct and click "OK".

Next, create a table around this list by going to the Insert tab and selecting "Table" in the Table group (make sure that the list is still high-lighted before selecting "Table"). Check that the details are correct and click "OK". You now have a table that will expand and contract as you add or remove sheet names.

Next, place the following amended code in a standard module and assign it to a button:-


Code:
Sub TransferData()

    Dim ws As Worksheet, sh As Worksheet, sht As Worksheet
    Dim shRng As Range, lr As Long

    Set sht = Sheets("Sheet List")
    Set sh = Sheets("Master")
    Set shtRng = sht.Range("ShList")

Application.ScreenUpdating = False

sh.UsedRange.Offset(1).ClearContents

For Each ws In Worksheets
    If shtRng.Find(What:=ws.Name, LookAt:=xlWhole) Is Nothing Then
            lr = ws.Range("A" & Rows.Count).End(xlUp).Row
            Union(ws.Range("A2:F" & lr), ws.Range("I2:U" & lr), ws.Range("W2:AH" & lr)).Copy
            sh.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues
       End If
Next ws

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Every sheet that you place in the ShList will now be excluded from the data transfer. If you wish that certain sheets be included in future then just remove them from the ShList.

Make sure that the Master and Sheet List names are always in the ShList.

So that everyone is clear on what is happening, following is the link to a sample file that I created for you to play with. Click on the "RUN" button to see it work.You will see that only data from sheet2 and sheet3 will be transferred to the Master sheet. Hence, if you only have the excluded sheets in the Sheet List, the remaining ten of your source sheets will have their data transferred over to the Master sheet.

http://ge.tt/5pMYFlm2


To prevent duplication in the Master sheet, all previous data is cleared prior to a new data transfer being executed.

Test the code in a copy of your work book first.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Wow! This works beautifully! However there is an error in the code. Dim shRng As Range needs to be Dim shtRng as Range. I can't thank you enough. What a great set of code! Thank you for your help on this. The table is an excellent idea.
 
Upvote 0
Oops! Typo! well picked up Grimm! Glad to see that you actually read through the code line by line. It may have been better to actually use something completely different. Too many S's and Sh's as I look back at it.

Anyway, its now working for you. Glad that I was able to help.

I'll leave it to you to mark the thread as solved.


Cheerio,
vcoolio.
 
Upvote 0
That's a great point! Yes, I read the code because it helps me better understand how to use it and modify it if I have too. I use it lot for business just wish there was a good book to use VBA for business applications like PnL's Sales etc. How do I close it out? I didn't know. lol. Again thank you!
 
Upvote 0
Well Grimm. Looks like you and I both are stumped on that one! There used to be a section in the thread tools that allowed one to mark a thread as solved. Can't find it either!

Anyway, anyone that may come by this way will realise that its done and dusted.

BTW, you may find some helpful books, CDs, videos etc. here:-

https://www.mrexcel.com/store/index.php

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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