Results 1 to 32 of 32

VBA code to copy, paste and transpose every 5th row from multiple worksheets

Threaded View

  1. #29
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA code to copy, paste and transpose every 5th row from multiple worksheets

    It is because of the formula references in each sheet. We can make a simple change from pasteall to pastevalues. I believe that may correct it (Note: It is pulling data in column AE and every column to the right)

    Sub Copy_Data()
    Dim fWS As Worksheet:   Set fWS = Sheets("Statatest")
    Dim ws1 As Worksheet:   Set ws1 = Sheets("Productivity")
    Dim ws As Worksheet
    Dim iCol As Long, LC As Long, LR As Long, aCount As Long
    
    Application.ScreenUpdating = False
    
    For Each ws In Worksheets
        Select Case ws.Name
            Case Is = fWS.Name
                'do nothing
            Case Is = ws1.Name
                aCount = 3
                ws1.Range("B6:B" & ws1.Range("B" & Rows.Count).End(xlUp).Row).Copy
                fWS.Range("C1").PasteSpecial xlPasteAll, Transpose:=True
                    LC = ws1.Cells(10, Columns.Count).End(xlToLeft).Column
                    If LC > 1 Then
                        For iCol = 3 To LC
                            LR = ws1.Cells(Rows.Count, iCol).End(xlUp).Row
                            ws1.Range(ws1.Cells(10, iCol), ws1.Cells(LR, iCol)).Copy
                                fWS.Range("C" & aCount).PasteSpecial xlPasteValues, Transpose:=True
                            aCount = aCount + 5
                        Next iCol
                    End If
            Case Is = "Terms of Trade"
                aCount = 4
                LC = ws.Cells(10, Columns.Count).End(xlToLeft).Column
                If LC > 30 Then
                    For iCol = 31 To LC
                        LR = ws.Cells(Rows.Count, iCol).End(xlUp).Row
                        ws.Range(ws.Cells(10, iCol), ws.Cells(LR, iCol)).Copy
                            fWS.Range("C" & aCount).PasteSpecial xlPasteValues, Transpose:=True
                        aCount = aCount + 5
                    Next iCol
                End If
            Case Is = "Debt"
                aCount = 2
                LC = ws.Cells(10, Columns.Count).End(xlToLeft).Column
                If LC > 30 Then
                    For iCol = 31 To LC
                        LR = ws.Cells(Rows.Count, iCol).End(xlUp).Row
                        ws.Range(ws.Cells(10, iCol), ws.Cells(LR, iCol)).Copy
                            fWS.Range("C" & aCount).PasteSpecial xlPasteValues, Transpose:=True
                        aCount = aCount + 5
                    Next iCol
                End If
            Case Is = "REER"
                aCount = 5
                LC = ws.Cells(10, Columns.Count).End(xlToLeft).Column
                If LC > 30 Then
                    For iCol = 31 To LC
                        LR = ws.Cells(Rows.Count, iCol).End(xlUp).Row
                        ws.Range(ws.Cells(10, iCol), ws.Cells(LR, iCol)).Copy
                            fWS.Range("C" & aCount).PasteSpecial xlPasteValues, Transpose:=True
                        aCount = aCount + 5
                    Next iCol
                End If
            Case Is = "FX"
                aCount = 6
                LC = ws.Cells(10, Columns.Count).End(xlToLeft).Column
                If LC > 30 Then
                    For iCol = 31 To LC
                        LR = ws.Cells(Rows.Count, iCol).End(xlUp).Row
                        ws.Range(ws.Cells(10, iCol), ws.Cells(LR, iCol)).Copy
                            fWS.Range("C" & aCount).PasteSpecial xlPasteValues, Transpose:=True
                        aCount = aCount + 5
                    Next iCol
                End If
        End Select
    Next ws
        
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by stnkynts; 11-08-2013 at 11:56 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Copy Paste Transpose Loop (Multiple Sheets)
    By demon8991 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-03-2013, 11:50 PM
  2. [SOLVED] Please help me to modify the code copy/paste/transpose
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-30-2013, 09:44 AM
  3. [SOLVED] What is the most efficient way to copy, paste and transpose values between worksheets?
    By fredrs05 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-18-2013, 03:51 PM
  4. Code to Copy & Paste Transpose Selected Information
    By tiger01 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2011, 01:02 AM
  5. Replies: 1
    Last Post: 05-11-2011, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1