2

I have the following code which currently works, but does not display the way I want it to. I am new to VBA so I used this template from the web.

It makes a sheet called "Archive" then prints all the data I have in 40 other sheets onto it. The problem is that it from reads top to bottom.

Public Sub m()
    Dim lRow As Long
    Dim sh As Worksheet
    Dim shArc As Worksheet
    Set shArc = ThisWorkbook.Worksheets("Archive")
    For Each sh In ThisWorkbook.Worksheets
        Select Case sh.Name
            Case Is <> "Archive"
                lRow = shArc.Range("A" & Rows.Count).End(xlUp).Row
                sh.Range("B1:M247").Copy 
                _Destination:=shArc.Range("A" & lRow)
        End Select
    Next
    Set shArc = Nothing
    Set sh = Nothing
End Sub

I want the macro to paste the data so that it is read from from left to right.

TLDR: code gathers data but pastes it all vertically. I want it to paste horizontally. can anyone alter it?

3
  • I proposed an edit that removed the <br /> and added code formatting to make your post more readable. Please double check that I didn't accidently delete a character around these two lines: sh.Range("B1:M247").Copy and _Destination:=shArc.Range("A" & lRow) Correct if needed. Commented Feb 25, 2018 at 12:57
  • So i tried editing the code with one of the replies here - it was in the correct orientation, but it only took the first column from each sheet. Each of the sheets I have 13 columns though. Commented Feb 25, 2018 at 13:30
  • I was just trying to edit to make the question more readable. Want to make sure I didn't add an error in the code block. Commented Feb 25, 2018 at 13:46

1 Answer 1

1

So i tried messing around some more and edited one of the earlier replies. This seems to work for my purposes at the moment

Public Sub m()
    Dim lCol As Long
    Dim sh As Worksheet
    Dim shArc As Worksheet
    Set shArc = ThisWorkbook.Worksheets("Archive")
    For Each sh In ThisWorkbook.Worksheets
        Select Case sh.Name
             'do nothing
        Case Else
            lCol = shArc.Cells(1, shArc.Columns.Count).End(xlToLeft).Column
            sh.Range("B1:M247").Copy _
              Destination:=shArc.Cells(1, lCol + 13)
    End Select
Next
    Set shArc = Nothing
    Set sh = Nothing
End Sub
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.