+ Reply to Thread
Results 1 to 4 of 4

Combine Worksheets, only keep Row 1 of first worksheet

  1. #1
    Registered User
    Join Date
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Combine Worksheets, only keep Row 1 of first worksheet

    Hi,

    I am running a macro that combines worksheets that are all laid out in the exact same format. Consequently, I only need Row 1 (the headers) from the first worksheet that is copied, I just need from Row 2 on for the other worksheets. This is my current code, which works fine for combining everything, except it includes Row 1 from all worksheets. Will you help me with what code I need to insert where? *ignore the <> "Main" stuff, that worksheet is not being combined, and is completely separate from this task.*

    'Combine the sheets
    For Each ws In Worksheets

    If ws.Name <> "Main" _
    And ws.Name <> "Create File" _
    And ws.Name <> "Save as DIF" _
    And ws.Name <> "Target" Then

    'Find last column with data
    nLastCol = ws.Cells(5, ws.Columns.Count).End(xlToLeft).Column

    'Find last row with data
    nLastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    'Define the range and copy
    ws.Range(ws.Cells(1, "A"), ws.Cells(nLastRow, nLastCol)).Copy

    'PasteSpecial
    With wsTarget
    nTargetLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    wsTarget.Range("A" & nTargetLastRow + 0).PasteSpecial
    End With
    End If
    Next ws

    With Application
    .DisplayAlerts = True
    .EnableEvents = True
    .ScreenUpdating = True
    End With

    End Sub

  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: Combine Worksheets, only keep Row 1 of first worksheet

    Hi j.Lancaster1

    It seems that:

    Please Login or Register  to view this content.
    is your culprit, try:

    Please Login or Register  to view this content.
    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
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Combine Worksheets, only keep Row 1 of first worksheet

    That makes perfect sense, thanks!

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

    Re: Combine Worksheets, only keep Row 1 of first worksheet

    You're welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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