+ Reply to Thread
Results 1 to 8 of 8

Loop through worksheets to copy data to new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    09-13-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Loop through worksheets to copy data to new workbook

    Hi SixthSense thanks for the reply! but I tried your macro it did not work...gave me a run time error 424
    I am not sure why because it worked in your sample file.
    So I attached my original file for your reference Raw Format.xlsm
    This is the exact file format I am working with except I removed the confidential data.
    What I want is as described in the post. Thanks!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Loop through worksheets to copy data to new workbook

    Try this slightly adjusted code….

    Sub ConsolidateData()
    Dim nEndRw As Long, Ws As Worksheet, nTemp As Long
    
    Sheets.Add , Sheets(Sheets.Count)
    Sheets(1).Range("B1:E1").Copy Range("A1")
    ActiveSheet.Move
    
    Application.ScreenUpdating = False
    
    For Each Ws In ThisWorkbook.Worksheets
        With Ws
                nEndRw = .Cells(Rows.Count, "D").End(xlUp).Row
            .Range("D2:D" & nEndRw).SpecialCells(xlCellTypeConstants, 23).Copy
                nEndRw = Cells(Rows.Count, "A").End(xlUp).Row + 1
            Cells(nEndRw, "A").PasteSpecial xlPasteValues, , True
                nTemp = Cells(Rows.Count, "A").End(xlUp).Row
            Range("B" & nEndRw & ":B" & nTemp).Value = .Range("F2").Value
            For Each r In Range("A" & nEndRw & ":A" & nTemp)
                r.Offset(, 2).Value = r.Value & r.Offset(, 1).Value
            Next r
            Range("D" & nEndRw & ":D" & nTemp).Value = .Name
        End With
    Next Ws
    
    Range("A1").CurrentRegion.EntireColumn.AutoFit
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    09-13-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Loop through worksheets to copy data to new workbook

    Hi SixthSense works like a charm! Thank you so much!!

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Loop through worksheets to copy data to new workbook

    Glad it helps you and thanks for the feedback and rep

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 07-02-2013, 07:49 AM
  2. Copy/Paste Range of Data from Multiple Workbooks/Worksheets to Master Workbook/Worksheets
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 08:21 PM
  3. Loop through range and copy to new workbook as seperate worksheets
    By thesasman2012 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2012, 10:25 AM
  4. Loop command macro to copy data between worksheets
    By ThunderBuck in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-12-2009, 11:55 AM
  5. Replies: 1
    Last Post: 04-01-2006, 03:50 PM

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