0
votes

I want to copy all columns from "B" until the end of the sheet into a new sheet named "combined". The Header table in sheets "Combined" is the same of every sheets ("A").

Sub Combine()

   ' Sheets(1).Select
   ' Worksheets.Add ' add a sheet in first place
    Sheets(1).Name = "Combined"

    ' copy headings
    Sheets(2).Activate
    Range("A1").EntireColumn.Select
    Selection.Copy Destination:=Sheets(1).Range("A1")

    Dim ws As Worksheet
    Dim wsDest As Worksheet

    Set wsDest = Sheets("Combined")

    For Each ws In ActiveWorkbook.Sheets
        If ws.Name <> wsDest.Name Then
            ws.Range("B1", ws.Range("B1").End(xlToRight).End(xlDown)).Copy
            wsDest.Cells(1, Columns.Count).End(xlToLeft).Offset("B").PasteSpecial xlPasteValues
        End If
    Next ws

End Sub
1
and what's the problem you're facing?DisplayName

1 Answers

1
votes

.Offset("B") isn't a valid syntax

to shift one column to the right you want .Offset(, 1)

Dim ws As Worksheet
Dim wsDest As Worksheet

Set wsDest = Sheets("Combined")

For Each ws In ActiveWorkbook.Sheets
    If ws.Name <> wsDest.Name Then
        ws.Range("B1", ws.Range("B1").End(xlToRight).End(xlDown)).Copy
        wsDest.Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).PasteSpecial xlPasteValues
    End If
Next ws