Consulting

Results 1 to 5 of 5

Thread: Copy Rows to Another Sheet Macro

  1. #1
    VBAX Newbie
    Joined
    Mar 2005
    Posts
    2
    Location

    Copy Rows to Another Sheet Macro

    How to copy from worksheet1 only rows with data to worksheet2. In both worksheets the first 2 rows contain headers. The headers should not be copied to worksheet2. Please solve using macro code

    Thanks in advance!

    jawsm

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    Welcome to VBAX!

    Providing that there is always data in column A (no rows that have a blank in A, but data in another column), try this:

    Sub copy()
    Dim i As Long, t As Long
    For i = 3 To ActiveSheet.Range("A65536").End(xlUp).Row
        If Application.WorksheetFunction.CountA(Range("A" & i & ":IV" & i)) > 0 Then
            t = t + 1
            Range("A" & i).EntireRow.copy Worksheets("Sheet2").Range("A" & t)
        End If
    Next i
    End Sub
    It will skip your headings, and then paste each row starting at A1 on Sheet2. (You may have to update "Sheet2" to the name of your worksheet if it is different.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Newbie
    Joined
    Mar 2005
    Posts
    2
    Location

    Solved

    Thanks for the solution, works like a charm!

    jawsm

  4. #4
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    jawsm: Please mark solved by clicking on Thread Tools dropdown at the top of the thread.

    Thanks! Glad you got it resolved!
    ~Anne Troy

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi jawsm!

    Glad you got it solved! I'll take care of marking this one solved.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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