0

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? Commented Dec 23, 2018 at 8:08

1 Answer 1

1

.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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.