+ Reply to Thread
Results 1 to 6 of 6

Macro to copy header row and data row in separate sheets

Hybrid View

  1. #1
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Macro to copy header row and data row in separate sheets

    Hello

    Try this
    Sub PagesByDescription()
    Dim rRange As Range, rCell As Range
    Dim wSheet As Worksheet
    Dim wSheetStart As Worksheet
    Dim strText As String
    
        Set wSheetStart = ActiveSheet
        wSheetStart.AutoFilterMode = False
        'Set a range variable to the correct item column
        Set rRange = Range("A1", Range("A65536").End(xlUp))
        
            'Delete any sheet called "UniqueList"
            'Turn off run time errors & delete alert
            On Error Resume Next
            Application.DisplayAlerts = False
            Worksheets("UniqueList").Delete
            
            'Add a sheet called "UniqueList"
            Worksheets.Add().Name = "UniqueList"
            
               'Filter the Set range so only a unique list is created
                With Worksheets("UniqueList")
                    rRange.AdvancedFilter xlFilterCopy, , _
                     Worksheets("UniqueList").Range("A1"), True
                     
                     'Set a range variable to the unique list, less the heading.
                     Set rRange = .Range("A2", .Range("A65536").End(xlUp))
                End With
                
                On Error Resume Next
                With wSheetStart
                    For Each rCell In rRange
                      strText = rCell
                     .Range("A1").AutoFilter 1, strText
                        Worksheets(strText).Delete
                        'Add a sheet named as content of rCell
                        Worksheets.Add().Name = strText
                        'Copy the visible filtered range _
                        (default of Copy Method) and leave hidden rows
                        .UsedRange.Copy Destination:=ActiveSheet.Range("A1")
                        ActiveSheet.Cells.Columns.AutoFit
                    Next rCell
                End With
                
            With wSheetStart
                .AutoFilterMode = False
                .Activate
            End With
            
            On Error GoTo 0
            Application.DisplayAlerts = True
    End Sub
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  2. #2
    Forum Contributor aganesan99's Avatar
    Join Date
    04-26-2013
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Macro to copy header row and data row in separate sheets

    Thanks Fotis for your timely help

    aganesan99

  3. #3
    Forum Contributor aganesan99's Avatar
    Join Date
    04-26-2013
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Macro to copy header row and data row in separate sheets

    Hi Fotis,

    I have a row above the header column and it is also getting copied.

    I don't want that to happen. Can you help?

    Thanks,
    aganesan99

+ 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. [SOLVED] Macro to copy and paste based on criteria to 11 separate sheets
    By msmith7113 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2013, 02:30 AM
  2. [SOLVED] Excel vba copy data from general sheets and organize them in separate sheets.
    By excelsubb in forum Excel Programming / VBA / Macros
    Replies: 40
    Last Post: 01-24-2013, 08:01 AM
  3. Replies: 3
    Last Post: 06-12-2012, 01:33 PM
  4. Copy and paste data to separate sheets based on mutiple criteria again
    By Ricker090 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-13-2011, 02:23 PM
  5. Copy and paste data to separate sheets based on mutiple criteria
    By Ricker090 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2011, 03:48 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