+ Reply to Thread
Results 1 to 10 of 10

How to split worksheet into multiple worksheets based on column content

Hybrid View

  1. #1
    Registered User
    Join Date
    06-03-2014
    Posts
    6

    Re: Code does not work

    This excel doc is sent to me every week (like it is) and I have been "long-hand" copying the data to new worksheets; deleting the branches that I don't need on that worksheet; renaming the worksheet to match the branch; then once I have a worksheet for each branch, I insert a module that breaks the worksheets into individual documents. I was hoping to find an easier way to break up the data into the different worksheets, instead of the long-hand way.

  2. #2
    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: How to split worksheet into multiple worksheets based on column content

    Let's try this one.
    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("G1", Range("G65536").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 7, 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.

  3. #3
    Registered User
    Join Date
    06-03-2014
    Posts
    6

    Re: How to split worksheet into multiple worksheets based on column content

    OUTSTANDING! Thank you so much! This will help me immensely!!!!

+ 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] Code locks cells when inserted in sheet module but returns error in standard module
    By yoda66 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2014, 07:39 AM
  2. Replies: 1
    Last Post: 08-30-2011, 02:23 AM
  3. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  4. Replies: 2
    Last Post: 03-27-2009, 11:48 AM
  5. Replies: 1
    Last Post: 04-10-2005, 07:07 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