VB Code for copying the same range from multiple sheets into a new sheet

ATY807

New Member
Joined
Mar 18, 2020
Messages
12
Office Version
  1. 2013
Platform
  1. Windows
I have a workbook which has multiple tabs arranged in the same format. I need to select the same range from each of these tabs and paste them all into a new sheet where this range of data from each tab appears at the end of the previous one. Could someone please help with the VB code.
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    5.7 KB · Views: 10
  • Capture2.PNG
    Capture2.PNG
    8 KB · Views: 10

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Would you please explain in words what range your wanting to copy.
I cannot determine from the image the range to copy.

Please say something like:
The Range("A1: G45")
 
Upvote 0
Like "My Answer Is This" alluded to, this should work with your Range.
It will add a sheet and name it "Master". If a Sheet with that name already exist, it will delete it so be careful.
Change your range to be copied and pasted as required.
VBA Code:
Sub Maybe()
Dim ws As Worksheet, a As String, i As Long
Application.ScreenUpdating = False
a = ActiveSheet.Name
On Error Resume Next
    Set ws = Sheets("Master")
        If Not ws Is Nothing Then
            Application.DisplayAlerts = False
                Worksheets("Master").Delete
            Application.DisplayAlerts = True
        End If
    Set ws = Nothing
On Error GoTo 0

Worksheets.Add(, Sheets(Sheets.Count)).Name = "Master"
    For i = 1 To ActiveWorkbook.Sheets.Count - 1
        With Sheets("Master")
            .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Resize(8, 9).Value = Sheets(i).Range("A1" & ":I8").Value
        End With
    Next i
Sheets(a).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Alternative suggestion, clears Master sheet contents only if Master sheet already exists, otherwise adds a new sheet and names it "Master"
VBA Code:
Sub Master_of_Puppets()
   
    Dim s As Double: s = Timer
   
    Application.StatusBar = False
       
    Populate Add_Master
   
    Application.StatusBar = "Run time: " & Round(Timer - s, 2) & " seconds"

End Sub

Private Function Add_Master() As Worksheet
       
    On Error Resume Next
    Set Add_Master = Sheets("Master")
    On Error GoTo 0
       
    If Not Add_Master Is Nothing Then
        Add_Master.Cells.Value = ""
        Add_Master.Move after:=Sheets(Sheets.Count)
    Else
        Set Add_Master = Worksheets.add(after:=Sheets(Sheets.Count))
        Sheets(Sheets.Count).Name = "Master"
    End If
   
End Function


Private Sub Populate(ByRef wks As Worksheet)

    Dim x   As Long
    Dim s   As Double: s = Timer
   
    Application.ScreenUpdating = False
   
    For x = 1 To ThisWorkbook.Sheets.Count - 1
        wks.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(8, 9) = Sheets(x).Cells(1, 1).Resize(8, 9).Value
    Next x
    wks.Activate
   
    Application.ScreenUpdating = True
       
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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