+ Reply to Thread
Results 1 to 3 of 3

Create new worksheet for each set of unique values

Hybrid View

popfan Create new worksheet for each... 01-16-2012, 01:34 PM
arlu1201 Re: Create new worksheet for... 01-16-2012, 01:59 PM
popfan Re: Create new worksheet for... 01-16-2012, 02:35 PM
  1. #1
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Create new worksheet for each set of unique values

    I am looking to try to create a macro that will be able to create a new worksheet with naming schema and copy and paste all rows of a table based on the unique value in column A. I would like the naming schema to be based on that unique value with a table. Attached is a worksheet that will create the new worksheets(run Regionwks on the unique worksheet) , but I cannot figure out how to copy and paste those unique rows in the Main worksheet to the new worksheet.
    Attached Files Attached Files
    Last edited by popfan; 01-16-2012 at 02:36 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Create new worksheet for each set of unique values

    Your way of getting the solution will work as well, though you will need to use the autofilter and the unique list that you have ready. I have worked out a different method which does not use autofilter but solves your issue. Try this code -
    Option Explicit
    Dim lrow As Long
    Dim i As Long
    Dim SName As Variant
    
    Sub copy_rows()
    
    Application.ScreenUpdating = False
    
    With Worksheets("Main")
    lrow = .Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 2 To lrow
            SName = Trim(.Range("A" & i).Value)
            If Not Evaluate("ISREF('" & SName & "'!A1)") Then
                Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = SName
                .Range("A1:H1").Copy Worksheets(SName).Range("A1")
            End If
                .Range("A" & i & ":H" & i).Copy Worksheets(SName).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        Next i
    End With
    
    Application.ScreenUpdating = True
    End Sub
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Create new worksheet for each set of unique values

    Thanks!! Perfect.

+ 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