Copy data from multiple shheets to master sheet VBA

cams88

New Member
Joined
Mar 23, 2020
Messages
21
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I want to copy data from multiple sheets (dynamic columns and rows) to one master sheet but my code doesn't work and i don't have any idea where is a problem... I would be very grateful for any help.

My code:

Sub copy_data_to_master_sheet()

Rowsnotmaster = Range("A1048576").End(xlUp).Row
Columnsnotmaster = Range("XFD3").End(xlToLeft).Column

For i = 2 To Worksheets.Count

'copy data from multiple sheets

Worksheets(i).Range(Cells(3, 1), Cells(Rowsnotmaster, Columnsnotmaster)).Copy
Worksheets("Master").Select

'paste data to master sheet

Master_row = Cells(Rows.Count, 1).End(xlUp).Row + 1
Selection.Cells(Master_row, 1).PasteSpecial

Next

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try:
VBA Code:
Sub Tango()

    Dim a   As Variant
    Dim w   As Worksheet
    Dim m   As Worksheet: Set m = Sheets("Master")
    
    Application.ScreenUpdating = False
    
    For Each w In ThisWorkbook.Worksheets
        If w.Name <> m.Name Then
            With w
                a = .Cells(3, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - 2, .Cells(3, .Columns.Count).End(xlToLeft).Column).Value
            End With
            m.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(a, 1), UBound(a, 2)).Value = a
        End If
    Next w
    
    Application.ScreenUpdating = True
    
    m.Activate
    
    Set m = Nothing: Erase a

End Sub
 
Upvote 0
It doesn't work:

1586371588640.png
 
Upvote 0
On what line does that occur?

I created a workbook with 3 sheets, Master, Data and Data (2)

In Data I filled A3:O25 with "X"
In Data (2) I filled A3:J40 with "A"

Ran macro and Master contains values of "X" in range A2:O24 and "A" in Range A25:J62 without any errors
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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