boilermaker1997
New Member
- Joined
- Sep 20, 2007
- Messages
- 41
I've modified some VBA code that I want to use to combine the content of 7 worksheets in a workbook. The worksheets are named "BVCZ2", "BVET", "BVIMA", "BVISI", "CCEDC", "CHINA", "PTBV". When I run the VBA code, it copies the content from the first worksheet (BVCZ2) 7 times rather than moving to the next. Could someone please help me with the error in my coding?
Coding as follows:
Sub Combine2()
Dim J As Worksheet
On Error Resume Next
' copy headings
Sheets("BVCZ2").Activate
Range("A4").EntireRow.Select
'Selection.Copy Destination:=Sheets(1).Range("A1")
Selection.Copy Destination:=Sheets("Combined").Range("A1")
' work through sheets
For Each J In ActiveWorkbook.Sheets(Array("BVCZ2", "BVET", "BVIMA", "BVISI", "CCEDC", "CHINA", "PTBV"))
Sheets(J).Activate ' make the sheet active
Range("A4").Select
Selection.CurrentRegion.Select ' select all cells in this sheets
' select all lines except title
'Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Offset(4, 0).Resize(Selection.Rows.Count - 1).Select
' copy cells selected in the new sheet on last line
Selection.Copy Destination:=Sheets("combined").Range("A65536").End(xlUp)(2)
Next
End Sub
Coding as follows:
Sub Combine2()
Dim J As Worksheet
On Error Resume Next
' copy headings
Sheets("BVCZ2").Activate
Range("A4").EntireRow.Select
'Selection.Copy Destination:=Sheets(1).Range("A1")
Selection.Copy Destination:=Sheets("Combined").Range("A1")
' work through sheets
For Each J In ActiveWorkbook.Sheets(Array("BVCZ2", "BVET", "BVIMA", "BVISI", "CCEDC", "CHINA", "PTBV"))
Sheets(J).Activate ' make the sheet active
Range("A4").Select
Selection.CurrentRegion.Select ' select all cells in this sheets
' select all lines except title
'Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Offset(4, 0).Resize(Selection.Rows.Count - 1).Select
' copy cells selected in the new sheet on last line
Selection.Copy Destination:=Sheets("combined").Range("A65536").End(xlUp)(2)
Next
End Sub