Forum Discussion

Phishdawg's avatar
Phishdawg
Brass Contributor
Apr 05, 2023

Moving Items from Sheet to Sheet

I am in receipt of an Excel workbook with ten sheets that each have more than 50,000 lines of data.

I have made a tables of all data on each sheet.

The client wants all data on one sheet (for other data manipulation later).

How can I best achieve the task of moving more than 50,000 lines of data from 10 different sheets to the first sheet, in sequence?

 

17 Replies

  • Patrick2788's avatar
    Patrick2788
    Silver Contributor

    Phishdawg 

    If you have Excel 365, you can use VSTACK:

    The sample workbook is rolling up sheets 1 to 3.

    =LET(
        header, Sheet1!A1:E1,
        stack, VSTACK(Sheet1:Sheet3!A2:E100),
        filtered, FILTER(stack, TAKE(stack, , 1) <> ""),
        VSTACK(header, filtered)
    )

     

      • Patrick2788's avatar
        Patrick2788
        Silver Contributor
        You've got a circular reference. You'll want to pull the 'header' from any of the sheets but not from the sheet with the formula.
  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    Phishdawg 

    One way to move data from multiple sheets to a single sheet in an Excel workbook is to use a formula.

    You can use the INDIRECT and ROW functions to reference the data on each sheet and copy it to the first sheet. Here’s an example formula that you can use:

    =INDIRECT("'Sheet" & CEILING(ROW()/50000,1) & "'!A" & MOD(ROW()-1,50000)+1)

    This formula will reference data from Sheet1 through Sheet10 and copy it to the first sheet in sequence. You can adjust the formula to match the number of rows and sheets in your workbook.

     

    You can also use VBA (Visual Basic for Applications) to write a macro that will automate this process for you. This method requires some knowledge of programming and may be more complex than using a formula.

    Here is an example of a VBA code that you can use to move data from multiple sheets to the first sheet in an Excel workbook:

    Sub MoveData()
        Dim ws As Worksheet
        Dim lastRow As Long
        Dim i As Long
    
        ' Set the starting row for the data on the first sheet
        lastRow = 1
    
        ' Loop through all sheets in the workbook
        For Each ws In ThisWorkbook.Worksheets
            ' Skip the first sheet
            If ws.Index > 1 Then
                ' Find the last row with data on the current sheet
                i = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
                ' Copy the data from the current sheet to the first sheet
                ws.Range("A2:A" & i).EntireRow.Copy Destination:=Sheets(1).Cells(lastRow, "A")
    
                ' Update the starting row for the next sheet
                lastRow = lastRow + i - 1
            End If
        Next ws
    End Sub

    This code will loop through all sheets in the workbook, except for the first one, and copy the data from each sheet to the first sheet in sequence. You can adjust the code to match your specific needs.

    To use this code, open the VBA editor in Excel by pressing Alt + F11.

    Then, insert a new module and paste this code into it.

    You can then run the macro by pressing F5 or by selecting it from the Macros menu.

    • Phishdawg's avatar
      Phishdawg
      Brass Contributor
      Where would I place the formula in the existing workbook?

      Should I create a new blank sheet and place it first, so I can capture all sheets?

      Does the formula go in cell A1 of sheet 1?

      =INDIRECT("'Sheet" & CEILING(ROW()/50000,1) & "'!A" & MOD(ROW()-1,50000)+1)

Resources