+ Reply to Thread
Results 1 to 5 of 5

Macro: Split worksheet into tabs.

Hybrid View

TWent Macro: Split worksheet into... 11-17-2010, 01:11 PM
StephenR Re: Macro: Split worksheet... 11-17-2010, 01:16 PM
TWent Re: Macro: Split worksheet... 11-17-2010, 01:33 PM
StephenR Re: Macro: Split worksheet... 11-17-2010, 01:49 PM
TWent Re: Macro: Split worksheet... 11-17-2010, 03:48 PM
  1. #1
    Registered User
    Join Date
    10-14-2010
    Location
    WI
    MS-Off Ver
    Excel 2007
    Posts
    77

    Macro: Split worksheet into tabs.

    Hello once again, I am tasked with splitting apart a report into different tabs so that those tabs can be saved as a .pdf on different pages. Then I need to split those.

    I will try to be a clear as possible to make this easy for myself .
    -Sorting by Unit number(value) in column B.
    -Every one has the same header.
    -Each tab has the name of the unit number.

    I will add an example of the report I need to break into these tabs.

    Basically this macro will search column B for a value then take all rows with the same value in column B and paste it into a new tab with a set header.
    Attached Files Attached Files
    Last edited by TWent; 11-17-2010 at 03:48 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro: Split worksheet into tabs.

    Try this:
    Sub Macro2()
     
    Dim r As Range, r2 As Range, ws As Worksheet
     
    Application.DisplayAlerts = False
    
    With Sheets("General Information")
        Sheets.Add().Name = "Temp"
        .Range("B2", .Range("B2").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("Temp").Range("A1"), Unique:=True
        Set r = Sheets("Temp").Range("A2", Sheets("Temp").Range("A2").End(xlDown))
         For Each r2 In r
            .Range("A2").AutoFilter field:=2, Criteria1:=r2
            Set ws = Worksheets.Add(After:=Worksheets(Worksheets.Count))
            .AutoFilter.Range.Copy ws.Range("A1")
            ws.Name = r2
        Next r2
        Sheets("Temp").Delete
        .AutoFilterMode = False
    End With
     
    Application.DisplayAlerts = True
        
    End Sub

  3. #3
    Registered User
    Join Date
    10-14-2010
    Location
    WI
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Macro: Split worksheet into tabs.

    Wow. That worked like a charm. Thanks for the pretty much instant response. Umm is there a way to make it paste in the same format. Making it so I do not have to fit to row width on each and every tab. My real report will have about 30 tabs.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro: Split worksheet into tabs.

    Can you clarify what you mean? If you mean column width, add this line before the Next:
    ws.Range("A:H").EntireColumn.AutoFit

  5. #5
    Registered User
    Join Date
    10-14-2010
    Location
    WI
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Macro: Split worksheet into tabs.

    Yup thats all I wanted.

+ 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