Exclude a Worksheet When Copying Data with Excel VBA
Question details
Exclude the destination worksheet from a VBA loop that copies data from other worksheets.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A macro consolidates the range B7:EA46 from worksheets into a sheet named Comb.
- Observed behavior
- The loop also processes the Comb destination sheet, and the user wants to avoid selecting or activating worksheets.
Confirm that the workbook containing the macro has a worksheet named Comb and that B7:EA46 is the intended source range. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file.
Skip the destination sheet and qualify both ranges
Use a worksheet condition and explicit source and destination references to copy data without selecting sheets.
The macro uses ThisWorkbook, so it processes worksheets in the workbook containing the code. It copies all cells in B7:EA46, including formatting, from every worksheet except Comb.
The destination row is calculated from the last populated cell in column B, plus two rows. Ensure column B reliably identifies the end of the existing data; otherwise, the next pasted block may overlap existing data.
In Excel, open the workbook and choose Developer > Visual Basic. If the Developer tab is hidden, enable it in Excel's ribbon settings.
In the VBA editor, choose Insert > Module and paste this code: Sub CopyDataMod() Dim Sh As Worksheet Dim Dest As Worksheet Dim NextRow As Long Set Dest = ThisWorkbook.Worksheets("Comb") For Each Sh In ThisWorkbook.Worksheets If Sh.Name <> Dest.Name Then NextRow = Dest.Cells(Dest.Rows.Count, "B").End(xlUp).Row + 2 Sh.Range("B7:EA46").Copy Dest.Cells(NextRow, "B").PasteSpecial Paste:=xlPasteAll End If Next Sh Application.CutCopyMode = False End Sub
Return to Excel, choose Developer > Macros, select CopyDataMod, and click Run. Check the Comb sheet to confirm the copied blocks are in the expected positions.

Consolidate spreadsheet data with WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format support, making it easy to move between office tools. Use WPS Spreadsheets to copy source ranges into a consolidation sheet; Excel VBA compatibility can vary by version and setup.

Frequently Asked Questions
How does the macro exclude the Comb sheet?
The condition If Sh.Name <> Dest.Name Then skips the worksheet assigned to Dest, which is ThisWorkbook.Worksheets("Comb").
Can I use a different destination sheet name?
Yes. Change "Comb" in Set Dest = ThisWorkbook.Worksheets("Comb") to the exact name of your destination worksheet.
Why does the macro start pasting at B3 on an empty sheet?
On an empty column B, End(xlUp) returns row 1, and the code adds two to that row number. Change the NextRow calculation if the first block should start elsewhere.
Does this macro copy formatting as well as values?
Yes. PasteSpecial with xlPasteAll copies all available cell content and formatting. To copy only values, replace xlPasteAll with xlPasteValues.
Will hidden worksheets be included?
Yes. The For Each loop processes all worksheets in ThisWorkbook except Comb, including hidden worksheets. Add a visibility condition if you want to skip hidden sheets.




