Copy data from multiple identical sheets to a consolidation sheet by macro

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,023
Office Version
  1. 365
Platform
  1. Windows
I have a workbook consisting of 9 sheets. The layout of each sheet is identical. Sheet 1 (named Combined report) and sheets 2 to 9 will auto-name based on the employees name
which I shall enter into cell A3 as each new sheet is taken into use.

What I would like to do is to have a macro or command button that will copy the contents of each sheet (sheets 2-9) and paste them onto sheet 1 (Combined report) in sheet order, i.e. starting at
cell A4, copy sheet 2, however many lines that may be, and then sheet 3 and so on until all sheets (2 - 9) and copied and pasted.

The data on each sheet to be copied is within the range A4:L4 but the number of rows is variable. It might be one row or 20 rows.

Any help will be very much appreciated!

Mel
 
Aah, no but i can make it so that it does. Done that and, of course, it works but on the Combined report sheet it on each row, instead of pasting the contents of sheet 2, 3 etc column A (i.e. Smith, Jones) it copies the contents of cell A3 on the Combined report sheet.

Mel
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Is there any column that will always have data on every row?
 
Upvote 0
No. On each sheet in A3:L3 there is column headers but below that each sheet is blank until i enter data. Does that make sense?

Mel
 
Upvote 0
Does that make sense?
No because that means there is nothing to copy.
Once you have entered data is there any particular column that will always have a value?
 
Upvote 0
Yes, on sheets 2 - 9, if I enter data cell B will always have a value.

Mel
 
Upvote 0
In that case, how about
VBA Code:
Sub MelSmith()
   Dim Ws As Worksheet, wsCom As Worksheet
   
   Set wsCom = Sheets("Combined Report")
   For Each Ws In Worksheets
      If Ws.Name <> wsCom.Name Then
         Ws.Range("A4:L" & Ws.Range("B" & Rows.Count).End(xlUp).Row).Copy wsCom.Range("A" & Rows.Count).End(xlUp).Offset(1)
      End If
   Next Ws
End Sub
 
Upvote 0
Hmmm. I have a command button assigned to the (new) macro MelSmith. When I execute the button, nothing happens... I have removed the two previous sets of code. Sheets 2, 3 and 4 have data in A4:L5, A4:L6 and A4:L7 respectively.

Mel
 
Upvote 0
How about
VBA Code:
Sub MelSmith()
   Dim Ws As Worksheet, wsCom As Worksheet
   Dim UsdRws As Long
   
   Set wsCom = Sheets("Combined Report")
   For Each Ws In Worksheets
      If Ws.Name <> wsCom.Name Then
         UsdRws = Ws.Range("B" & Rows.Count).End(xlUp).Row
         If UsdRws > 3 Then Ws.Range("A4:L" & UsdRws).Copy wsCom.Range("B" & Rows.Count).End(xlUp).Offset(1, -1)
      End If
   Next Ws
End Sub
 
Upvote 0
Try stepping through the code using F8, does it ever move to the .Copy part of the code?
 
Upvote 0

Forum statistics

Threads
1,215,915
Messages
6,127,691
Members
449,398
Latest member
m_a_advisoryforall

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