+ Reply to Thread
Results 1 to 5 of 5

Transferring data from multiple sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Transferring data from multiple sheets

    Hi folks

    I have to following code:

    Worksheets("GW").Range(Range("E7"), Range("E500").End(xlUp)).Copy
        Worksheets("FINAL").Range("A2").Insert shift:=xlDown
    
    Worksheets("GW").Range(Range("D7"), Range("D500").End(xlUp)).Copy
        Worksheets("FINAL").Range("B2").Insert shift:=xlDown
        
    Worksheets("GW").Range("O5").Copy
        Worksheets("FINAL").Range("B500").End(xlUp).Offset(2, 0).PasteSpecial Paste:=xlPasteValues
    the idea being that it transfers a varied range of data from one sheet into another - easy!

    however, I have 9 different sheets that I want this to apply to and all data to get transferred into the FINAL sheet.

    Any ideas how to simplify the code in order to do this?

    I tried a FOR EACH code but got twisted round.

    any help would be great.

    TVM
    Cry Havoc, let loose the Dogs of War

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Transferring data from multiple sheets

    Something like this:

    Sub Superdonk(): Dim ws As Worksheet, wf As Worksheet, c As Long, SNames As String, n As Integer
            SNames = Array(" ", "GW", "GW", "GW", "GW", "GW", "GW", "GW", "GW", "GW")
                            Set wf = Sheets("Final")
                    For n = 1 To UBound(SNames): Set ws = Sheets(SNames(n))
                            ws.Range(Range("E7"), Range("E500").End(xlUp)).copy
                                c = c + 1: wf.Cells(2, c).Insert Shift:=xlDown
    
                            ws.Range(Range("D7"), Range("D500").End(xlUp)).copy
                                c = c + 1: wf.Cells(2, c).Insert Shift:=xlDown
        
                                    ws.Range("O5").copy
        wf.Range("B500").End(xlUp).Offset(2, 0).PasteSpecial Paste:=xlPasteValues
                    Next n
    End Sub
    Rewrite the reds
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: Transferring data from multiple sheets

    Thanks for the quick reply...however...

    I get an 'Expected Array' error on the following line:

    For n = 1 to UBound
    it specifically highlights the 'UBound'

    ideas?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Transferring data from multiple sheets

    Maybe:

    Sub superdonk()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "FINAL" Then
        With ws
            .Range("E7:E500").Copy
            Sheets("FINAL").Range("A2").Insert xlDown
            .Range("D7:D500").Copy
            Sheets("FINAL").Range("B2").Insert xlDown
            .Range("O5").Copy
            Sheets("FINAL").Range("B500").End(xlUp).Offset(2, 0).PasteSpecial xlPasteValues
        End With
    End If
    Next ws
    End Sub

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Transferring data from multiple sheets

    Hi Superdonk,

    I should have declared SNames as Variant:

    Sub Superdonk(): Dim ws As Worksheet, wf As Worksheet, c As Long, SNames, n As Integer
            SNames = Array(" ", "GW", "GW", "GW", "GW", "GW", "GW", "GW", "GW", "GW")
                            Set wf = Sheets("Final")
                    For n = 1 To UBound(SNames): Set ws = Sheets(SNames(n))
                            ws.Range(Range("E7"), Range("E500").End(xlUp)).copy
                                c = c + 1: wf.Cells(2, c).Insert Shift:=xlDown
    
                            ws.Range(Range("D7"), Range("D500").End(xlUp)).copy
                                c = c + 1: wf.Cells(2, c).Insert Shift:=xlDown
        
                                    ws.Range("O5").copy
        wf.Range("B500").End(xlUp).Offset(2, 0).PasteSpecial Paste:=xlPasteValues
                    Next n
    End Sub

+ 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. Transferring data between sheets?
    By Bandolin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2014, 03:21 PM
  2. Transferring data and creating multiple sheets with chart
    By ruelfajardo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2013, 03:06 AM
  3. Replies: 0
    Last Post: 08-16-2010, 12:27 PM
  4. Transferring Data From Multiple sheets into one
    By Mayank.trivedi in forum Excel General
    Replies: 2
    Last Post: 03-01-2010, 11:54 PM
  5. [SOLVED] Transferring Data Between Sheets
    By Neil M in forum Excel General
    Replies: 8
    Last Post: 05-12-2006, 10:35 AM

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