Copy a Range of Data from Multiple Worksheets into a different Master Workbook

kmarkle

New Member
Joined
Jun 13, 2013
Messages
8
Hello- I have been searching for code that will help me copy a specific range of data from many worksheets within a workbook and paste it into a new workbook. I have worksheets names Day1-Day31 and I need to copy cells with data in the range from cells A69:C75 into the first blank row in a Master workbook. I know I can go back and forth activating the different workbooks and selecting each worksheet to accomplish this, but that would make for a very long code. Any advice would be appreciated. Thank you for you help in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

MixedUpExcel

Board Regular
Joined
Apr 7, 2015
Messages
212
Office Version
  1. 365
Platform
  1. Windows
Hi Kmarkle,

Try the code below:

It loops through all worksheets in the workbook and assuming that the only 2 sheets you don't want it to copy from are Master and Sheet1 (change if need be) then it will copy your range on each sheet and paste in the first blank cell in Column A on the Master Sheet.

Code:
Sub MasterSheet()


Dim LastRow As String
Dim ws As Worksheet


    For Each ws In ThisWorkbook.Worksheets
    
        If (ws.Name <> "Master") And (ws.Name <> "Sheet1") Then


    Sheets(ws.Name).Activate


    Range("A69:C75").Copy
    
    Sheets("Master").Activate
    
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With


    Range("A" & LastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
   :=False, Transpose:=False


        End If
        
    Next ws
    
End Sub

Hope this helps.

Simon
 
Upvote 0

MixedUpExcel

Board Regular
Joined
Apr 7, 2015
Messages
212
Office Version
  1. 365
Platform
  1. Windows
Hi Kmarkle,

I re-read your question and realised that you were saying that the Master Sheet wasn't on the same workbook as your Day 1 to Day 31.... so try this:

Make sure that you're Master Workbook isn't already open when you run this as it will ask you to open it (if it's open - it won't let you assign a name to use later in the code)


Code:
Sub MasterWorkbook()


Dim LastRow As String
Dim ws As Worksheet
Dim MasterWbk As String
Dim curWbk As String
curWbk = ActiveWorkbook.Name




    ChDrive "C"
    
    ChDir "C:\Users\Simon\Desktop\" ' put your own directory in here


    MYFILE = Application.GetOpenFilename("OPEN MASTER,*.*")
    
    Workbooks.Open Filename:= _
    MYFILE


    MasterWbk = ActiveWorkbook.Name


    Windows("" & curWbk).Activate


    For Each ws In ThisWorkbook.Worksheets
    
        If (ws.Name <> "Master") And (ws.Name <> "Sheet1") Then ' put the sheet names (if they are different in here - these will be in the Day 1 - Day 31 workbook


    Sheets(ws.Name).Activate


    Range("A69:C75").Copy
    
    Windows("" & MasterWbk).Activate
    
    Sheets("Sheet1").Activate
    
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With


    Range("A" & LastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
   :=False, Transpose:=False


    Windows("" & curWbk).Activate


        End If
        
    Next ws
    
End Sub
There may be an easier / better way of writing this but it worked for me.
 
Upvote 0

kmarkle

New Member
Joined
Jun 13, 2013
Messages
8
Hello- Thank you both for answering. I apologize for the delay in my response, but I was trying to figure it out on my own.

There are about 8 additional sheets in the workbook that I don't want to copy from.

Simon- I am trying your code but get a debugging error at

Sheets(ws.Name).Activate

Do I need to change Name to Master?

If you can remind me how to post code properly in this site I would also appreciate that.
Thank you again for your help.
 
Upvote 0

Forum statistics

Threads
1,195,988
Messages
6,012,714
Members
441,722
Latest member
tpaman1975

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
Top