Copy from multiple sheets and paste into sheet 1

Toby Kim

I am trying to get data from multiple worksheets and paste into sheet 1 but my code isnt working properly. It keeps copying from the sheet "table 1" over and over again. Does anyone know what is wrong with my code?

Thanks

Option Explicit

Sub test()

Dim ws As Worksheet
Dim i As Integer

    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Table 1" Then

            ActiveSheet.Range("A15:X35").Select
            Selection.Copy

            Worksheets("Table 1").Activate

                For i = 1 To 5000

                    If IsEmpty(Cells(i, 1)) = True And IsEmpty(Cells(i + 1, 1)) = True Then
                    ActiveSheet.Cells(i, 1).Select
                    ActiveSheet.Paste
                    Exit For
                    End If

                Next i

        End If
    Next ws

End Sub
A.S.H

Inside your loop, you are copying from the ActiveSheet, not from ws. if the activeSheet is "table 1" (in fact, you activate table 1 yourself in the statement Worksheets("Table 1").Activate), then of course if will keep copying from it.

Besides, it is always better to copy directly from ranges without using Activate and Select. I guess this is what you want to do:

With Worksheets("Table 1")
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Table 1" Then
            For i = 1 To 5000
                If IsEmpty(.Cells(i, 1)) And IsEmpty(.Cells(i + 1, 1)) Then
                    ws.Range("A15:X35").Copy .Cells(i, 1)
                    Exit For
                End If
            Next i
        End If
    Next ws
End With

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Copy colored cells from multiple sheets & paste into one sheet

Copy and paste values from multiple sheets in to summary sheet

Copying 1 column from multiple sheets into one sheet in the same workbook and them copy/paste a 2nd column from the same final sheet

Trying to copy data from multiple sheets one by one and paste to a different sheet.

Copy a range from sheet 1 and paste to next empty row on next sheets in loop

Copy and paste items from hidden sheets 2, 3 and 4 into sheet 1 if specific option chosen

VBA Copy Paste Values From Separate Ranges And Paste On Same Sheet, Same Row Offset Columns (Repeat For Multiple Sheets)

Copy same cell on all current and future sheets and paste on sheet 1

Loop Through Specific Sheets In Workbook And Copy/Paste To 1 overall Sheet

Copying data from multiple sheets into 1 sheet

Copy from a sheet in workbook1 to multiple sheets in workbook2

Excel VBA - Copy range from one sheet paste to all sheets after certain sheet in workbook

VBA - copy / paste one cell from multiple workseets to master sheet

VBA: multiple copy and paste from one sheet to another

Apps Script: Copy and paste rows from multiple source sheets to a mastersheet

VBA: copy values from multiple sheets & paste to another workbook

Copy row if value exists in both sheet 1 and sheet 2 and paste it to sheet 3. Google Sheets. Google Apps Script

Excel - Copy data from multiple sheets to one sheet

Copy specific columns from multiple sheets into one sheet

Copy range from multiple sheets rather than just one sheet

I need to copy a specific range in multiple sheets and paste them on a final sheet

How to copy values from one sheet and paste them into another using Google Sheets Macros?

Copy the last row ONLY from a Sheet and paste it to another sheets last row

Google Sheets + Apps Scripts, Copy/Paste from one sheet to another, but Paste into first empty cell in specific column (B)

Copy multiple workbooks and paste in a single sheet

Copy a row from Sheet1 and paste it into Sheet 2 if color of a cell is green

Excel VBA Copy Paste column from sheet 1 to sheet 2 if first row countain the word "End Date"

VBA copy/paste value from sheet 1 to sheet 2 on last used row?

Copy Used Range from Sheet1 and paste into Sheet3