Excel VBA master sheet copy-paste error 1004

robilika

New Member
Joined
Mar 28, 2018
Messages
1
Hello,


I am new to VBA formulas in excel.


I have a workbook with multiple sheets which needs to be copied(only values) in a master sheet in the same workbook. The problem is i get an error on one of my sheets: "Runtime error 1004 : The information cannot be pasted because the Copy area and the paste area are not the same size and shape" . i noticed that this error occurs only if i have only one row in my table that is not blank.






Here is my Formula :






Code:
Sub MockImportNewData()






Application.ScreenUpdating = False






Sheets("BLUGI").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("PANT").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("BLUZE").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("PULOVER").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False










Sheets("FUSTE").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("ROCHII").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("GECI").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("GEANTA").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("ACCESORII").Select


Range("A4:G4").Select


Range(Selection, Selection.End(xlDown)).Select


Selection.Copy


Sheets("MASTER").Select


Range("A3").Select


Selection.End(xlDown).Select


ActiveCell.Offset(1, 0).Select


Selection.PasteSpecial Paste:=xlPasteValues


Application.CutCopyMode = False






Sheets("Master").Select


Range("A5").Select






End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Are you trying to copy from all the sheets in your workbook?
And you mentioned "Tables" are we copying from tables on your sheet?
 
Last edited:
Upvote 0
Hi robilika,

Welcome to MrExcel!!

You don't have to select each tab to consolidate it. See how this goes:

Code:
Option Explicit
Sub Macro1()

    Dim wsMySheet   As Worksheet
    Dim wsConsSheet As Worksheet
    Dim lngLastRow  As Long
    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False
    
    Set wsConsSheet = Sheets("Master") 'Sheet for the data to be consolidated into. Change to suit.
    
    For Each wsMySheet In ThisWorkbook.Sheets
        If wsMySheet.Name <> wsConsSheet.Name Then
            lngLastRow = wsMySheet.Range("A:G").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            lngPasteRow = wsConsSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
            wsMySheet.Range("A4:G" & lngLastRow).Copy
            wsConsSheet.Range("A" & lngPasteRow).PasteSpecial xlPasteValues
        End If
    Next wsMySheet
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
If your trying to copy from all sheets into the Sheet named Master:
Try this:
Code:
Sub Copy_Ranges()
'Modified  4-2-18 2:05 AM EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrowa = 3
Dim i As Long
    
For i = 1 To Sheets.Count
    If Sheets(i).Name <> "Master" Then
        Lastrow = Sheets(i).Cells(Rows.Count, "A").End(xlUp).Row
        
        Sheets(i).Range("A4:G" & Lastrow).Copy
        Sheets("Master").Cells(Lastrowa, 1).PasteSpecial Paste:=xlPasteValues
        Lastrowa = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row + 1
    End If
Next
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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