+ Reply to Thread
Results 1 to 2 of 2

Splitting up part numbers in to different sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2011
    Location
    leeds
    MS-Off Ver
    Excel 2003
    Posts
    1

    Splitting up part numbers in to different sheets

    Hi

    Column 1 contains the part number and column 2 contains the socket codes it will fit into, there are 4 different sockets but over 1000 parts, what I am looking to do is have five sheets one for each socket. Parts are added to the database on a weekly biases.

    The socket numbers are; 10, 20, 30, 40 these will each have a separate sheet.

    PART 22 can either be used with a 20 socket or 2 number 10 sockets.

    Coloumn 1 Sockets
    PART 1 10
    PART 22 20
    PART 36 30
    PART 95 40

    Can someone help me on how to do this, any help is much appreciated.
    Last edited by M4JIC; 09-13-2011 at 06:27 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Splitting up part numbers in to different sheets

    the main sheet is called sheet1.

    try this macro (keep the function also in the same module)

    Sub test()
    Dim r As Range, rb As Range, sockets As Range, csocket As Range, x As String
    With Worksheets("sheet1")
    Set r = .Range("A1").CurrentRegion
    Set rb = Range(.Range("B1"), .Range("B1").End(xlDown))
    Set sockets = .Range("A1").End(xlDown).Offset(5, 0)
    rb.AdvancedFilter xlFilterCopy, , sockets, True
    Set sockets = Range(sockets.Offset(1, 0), sockets.End(xlDown))
    For Each csocket In sockets
    x = csocket.Value
    r.AutoFilter field:=2, Criteria1:=x
    r.Offset(1, 0).Resize(r.Rows.Count - 1, r.Columns.Count).SpecialCells(xlCellTypeVisible).Copy
    If Not SheetExists(x) Then
    Worksheets.Add
    ActiveSheet.Name = x
    Else
    GoTo nextstep
    End If
    nextstep:
    With Worksheets(x)
    .Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
    End With
    r.AutoFilter
    Next csocket
    End With
    
    End Sub

    Function SheetExists(SheetName As String) As Boolean
    ' returns TRUE if the sheet exists in the active workbook
        'taken from web
        SheetExists = False
        On Error GoTo NoSuchSheet
        If Len(Sheets(SheetName).Name) > 0 Then
            SheetExists = True
            Exit Function
        End If
    NoSuchSheet:
    End Function
    Sub undo()
    Dim j As Long
    Application.DisplayAlerts = False
    For j = Worksheets.Count To 1 Step -1
    If Worksheets(j).Name = "Sheet1" Then GoTo nextj
    Worksheets(j).Delete
    nextj:
    Next j
    With Worksheets("sheet1")
    Range(.Range("A1").End(xlDown).Offset(1, 0), .Cells(Rows.Count, "A")).EntireRow.Delete
    End With
    Application.DisplayAlerts = True
    
    End Sub

+ 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