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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,217,053
Messages
6,134,318
Members
449,865
Latest member
dhpaul1031

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