VBA for copying from multiple tabs to one master sheet

ExcelHelpNeeded99

New Member
Joined
Oct 6, 2017
Messages
13
There are lot of sheets in my workbook, some of the sheets are for personnel data and each employee has a tab of their own. I just want to copy from those sheets and I want to copy the data from column 3 and put it as a separate column in my Master sheet. The master sheet and all the individual personnel sheets have the same 1st column. I would like to include the sheet name (employee name Last, First) at the top of each column if possible.

- How do I tell the macro to only select certain sheets (Probably better to ignore 5 than select 105?)
- Please advise on the code for this.

Your help is greatly appreciated.

Thanks in advance.


Existing format

Row 1Blank columnData
(Row 2)First nameAdam
Last nameAnt
CompanyBand Co.
TitleSinger
.........

<tbody>
</tbody>

Desired combined "Master" sheet

Row 1BlankAnt, AdamBloggs, Joe
First nameAdamJoe
Last NameAntBloggs

<tbody>
</tbody>
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
This will loop through all sheets ignoring those in red (change to suit).
Code:
Sub CopyShtData()

    Dim Arr As Variant
    Dim Sht As Worksheet
    
    Arr = Array("Details", "Data List", "Exist")
    
    For Each Sht In Worksheets
        If Not UBound(Filter(Arr, Sht.Name, True, vbTextCompare)) >= 0 Then
            MsgBox Sht.Name
        End If
    Next Sht

End Sub
If you need help in copying the data over to the Master sheet, we'll need further info.
 
Upvote 0
Is the master sheet called "Master"?
Do you want to copy the entire col C from the employee sheets starting from row2?
From your description it looks like you wnat Col B on the master to be left blank, is that correct?
 
Upvote 0
Thanks Fluff. Yes I want to copy from each non red sheet starting at row 2 and going to row 31 just for the data in column C. The master sheet column A is populated with the same field titles as the other sheets and I would like to leave column B blank starting the values from the 1st sheet in column C and so on.

Ideally and I would be so grateful if this would be possible. I would copy the values from column A of the sheets into the master transposed so that they form the column headers and that each sheets data is copied in in separate rows.

Column 1Column 2Column 3Column 4….Column 29
Row 1First NameLast nameCompanyTitle etc
Data from 1st non red tabC2C3C4C5 C31
Data from 2nd non red tabC2C3C4C5 C31
Loop until end of non red sheets

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

I would be extremely grateful for either option.

Thanks
 
Upvote 0
Try this, changing sheets names to suit
Code:
Sub CopyShtData()

    Dim Arr As Variant
    Dim Sht As Worksheet
    Dim Rw As Long
    
    Arr = Array("[COLOR=#ff0000]Details[/COLOR]", "[COLOR=#ff0000]Data List[/COLOR]", "[COLOR=#ff0000]Exist[/COLOR]", "[COLOR=#ff0000]Master[/COLOR]")
    Rw = 2
    With Sheets("[COLOR=#ff0000]Master[/COLOR]")
        .Range("A1").Resize(, 30).Value = Application.Transpose(.Range("A2").Resize(30).Value)
        .Range("A2:A31").ClearContents
    End With
    For Each Sht In Worksheets
        If Not UBound(Filter(Arr, Sht.Name, True, vbTextCompare)) >= 0 Then
            Sheets("[COLOR=#ff0000]Master[/COLOR]").Range("A" & Rw).Resize(, 30).Value = Application.Transpose(Sht.Range("C2:C31").Value)
            Rw = Rw + 1
        End If
    Next Sht

End Sub
 
Upvote 0
Thanks again Fluff- this is awesome!
It is still copying from the red sheets but there aren't many of those and I can just delete that data in the master. What are the "Details", "Data List" and "Exist" in your vba? I am new to this so would appreciate the explanation if you have time.
Thanks so much!
 
Upvote 0
They are sheet names. You need to change them to match the names of the sheets you don't want to copy.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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