+ Reply to Thread
Results 1 to 2 of 2

unique values (range) to create new sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    11-22-2011
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2003
    Posts
    6

    Question unique values (range) to create new sheets

    Hi,

    Background:
    within the range H5-H1000 of the sheet ABC there are different or recurring statements.

    With this unique values i want to start the following procedure:

    1. take only the unique values out of this range; exclude empty-cells
    2. within the current excel-document, the following tasks have to take place:

    a) Sheets("ABC").Copy After:=Sheets(Variable)
    b) Sheets("ABC (Variable)").Name = "Unique Value"
    c) Selection.AutoFilter Field:=8, Criteria1:="Unique Value"

    Description:
    b = new sheets with sheet-labels of every unique value out of the already mentioned range
    c = the value for "Criteria1" has to be the same name as the corresponding sheet-label. Task c has to be executed for every new sheet (except the sheet ABC)

    Who can support me with the VB-Code for task 1, respectively the loop to complete tasks a-c ?

    thanks in advance

    Frank

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: unique values (range) to create new sheets

    Frank,

    Assuming that cell H4 of sheet 'ABC' is a header for data in H5:H1000, you should be able to use the following:
    Sub tgr()
        
        Dim rngDest As Range
        Dim arrUnq As Variant
        Dim arrIndex As Long
        Dim xlCalc As Integer
        
        Set rngDest = Cells(1, ActiveSheet.UsedRange.Column + ActiveSheet.UsedRange.Columns.Count + 1)
        
        With Application
            xlCalc = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
        
        With Range("H4:H1000")
            .AutoFilter 1, "<>"
            .Copy rngDest
            .AutoFilter
        End With
        
        With Range(rngDest, rngDest.End(xlDown))
            .AdvancedFilter xlFilterCopy, , .Offset(, 1), True
            arrUnq = Application.Transpose(Range(rngDest.Offset(1, 1), rngDest.Offset(, 1).End(xlDown)).Value)
            .Resize(, 2).EntireColumn.Delete
        End With
        
        For arrIndex = 1 To UBound(arrUnq)
            Sheets("ABC").Copy After:=Sheets(Sheets.Count)
            With ActiveSheet
                .Name = arrUnq(arrIndex)
                .UsedRange.AutoFilter 8, arrUnq(arrIndex)
            End With
        Next arrIndex
        
        With Application
            .Calculation = xlCalc
            .ScreenUpdating = True
        End With
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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