Consulting

Results 1 to 3 of 3

Thread: Filter data to pages based on number format

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Filter data to pages based on number format

    I have a worksheet with a column of book# formatted like 6032-11, 2349-5 , 7455-22 etc...etc..
    I want to format each number to a separate page based on the value to the left of the dash.
    The problem is that I don't know how many different book types I will have, and its possible that there's 4 0r 5 digits before the dash.

    How can I format each book type ( The numbers to the left of the - )to a separate page and leave the original page untouched. After filtering, I want to automatically SUM the Column H of each filtered sheet and retain the page headings.
    A VBA solution is preferred if possible.
    SEE ATTACHED WORKSHEET

    Any help appreciated.

    Thanks
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Sub blah()
    On Error GoTo here
    Application.ScreenUpdating = False
    With Sheets("Sheet1")
      lr = .Cells(.Rows.Count, "F").End(xlUp).Row
      Dim myFilters As New Collection
      .Range("F2:F" & lr).TextToColumns Destination:=.Range("I2"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Other:=True, OtherChar:="-", FieldInfo:=Array(Array(1, 1), Array(2, 9))
      On Error Resume Next
      For Each cll In .Range("I2:I" & lr).Cells
        myFilters.Add cll.Value, CStr(cll.Value)
      Next cll
      On Error GoTo here
      .AutoFilterMode = False
      With .Range("A1:I" & lr)
        .AutoFilter
        For Each filtr In myFilters
          .AutoFilter Field:=9, Criteria1:=filtr
          .Resize(, 8).Copy
          With Sheets.Add(After:=Sheets(Sheets.Count))
            .Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
            .Range("K1").FormulaR1C1 = "=SUM(R[1]C[-3]:R[" & .UsedRange.Rows.Count - 1 & "]C[-3])"
            .Range("J1").Value = "PO Total --->"
            .Columns("A:K").EntireColumn.AutoFit
            .Cells(1).Select
            .Name = "Prefix " & filtr
          End With
        Next filtr
        Application.CutCopyMode = False
      End With
      .AutoFilterMode = False
      .Range("I2:I" & lr).ClearContents
      .Activate
      .Range("A1").Select
    End With
    here:
    Application.ScreenUpdating = True
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks p45cal:

    It worked great. No problems.
    I had created a column with this formula =IF(F15>"",LEFT(F15,FIND("-",F15)-1),"") to get the numbers to the LEFT of the - ( The Prefix ), Then I was planning on doing the filter after that.
    Your solution is much more elegant and precise.
    Again.
    Thank You.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •