VBA - Enter worksheet names into a "Master Sheet" and copy data

jonny1984

New Member
Joined
Apr 27, 2012
Messages
20
Office Version
  1. 2016
Platform
  1. Windows
Hi there

I am trying to do something probably quite simple but read a few tutorials and been unable to figure it out..... so calling for help !!

I know I cant add attachments so have saved an Excel file into dropbox - link below

https://www.dropbox.com/s/jg8nwxr5s5tpaj1/World datas.xlsx?dl=0


I am looking for a macro / VBA code that when run will automatically populate the "Master sheet" with

1. The names of the workbooks contained within the file - this will change as we might delete some old workbooks and then add new workbooks in - would be great to have a button or a macro we can run to re populate essentially a "chapter list" of the workbooks

2. Then copy the data in each workbook which can be of varying number of rows.. from 5 to 100 say (but would always start in cell A1) into the Master sheet as well so it could easily be compared and charts/graphs drawn etc

I really hope that's clear .. the file uploaded is "fully populated" .. basically looking for a macro that if I delete all the cells in the "Master" sheet, would re populate them as they are currently !


Thank you in advance so much for your help !!

Jonny
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
In your post, all instances of "Workbooks" should read "Worksheets"

varying number of rows.. from 5 to 100 say (but would always start in cell A1)
The sample data is not like this. The data on all sheets are in column B only, starting at B6.
Please clarify what you need.
 
Upvote 0
In your post, all instances of "Workbooks" should read "Worksheets"


The sample data is not like this. The data on all sheets are in column B only, starting at B6.
Please clarify what you need.


Hi footoo

Sorry! I am not an Excel expert (as is probably painfully clear)

You are right it should be Worksheets is what I meant (I actually knew that just tired and writing late at night!)

You are also right the data in the sheet is in column -but it should be in column A .. it will be in column A when I have the actual sheet with working data


Thanks!
Jonny
 
Upvote 0
I have assumed that row 1 in the source sheets contains headers.
Also, your Master sheet doesn't make sense to me, so I have omitted the second column (the one with the sheet names).
See if this does what you want :
Code:
Sub Summary()
Dim col%, rw%, ws As Worksheet
col = 1
rw = 1
Application.ScreenUpdating = False
With Sheets("Master")
    .Cells.ClearContents
    For Each ws In Worksheets
        If Not ws.Name = "Master" Then
            col = col + 1
            rw = rw + 1
            ws.Range(ws.[A2], ws.Cells(Rows.Count, "A").End(xlUp)) _
                .Copy .Cells(2, col)
            .Cells(1, col) = ws.Name
            .Cells(rw, 1) = rw - 1
        End If
    Next
    .Cells.EntireColumn.AutoFit
End With
End Sub
 
Upvote 0
Also, if the second column of the Master sheet is omitted, no point in having sequential numbers in column A :
Code:
Sub Summary()
Dim col%, ws As Worksheet
col = 1
Application.ScreenUpdating = False
With Sheets("Master")
    .Cells.ClearContents
    For Each ws In Worksheets
        If Not ws.Name = "Master" Then
            col = col + 1
            ws.Range(ws.[A2], ws.Cells(Rows.Count, "A").End(xlUp)) _
                .Copy .Cells(2, col)
            .Cells(1, col) = ws.Name
        End If
    Next
    .Cells.EntireColumn.AutoFit
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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