Consulting

Results 1 to 8 of 8

Thread: custom sorting a group of data

  1. #1

    custom sorting a group of data

    I have my data broken out into 3 sections (under column D): M, P and Grouped. They are already sorted, so all of the M's are together, P's and Grouped.
    What I am trying to do is, find all M's and custom sort that area. Same thing for P's and Grouped.

    The data is from A:O

    any help would be greatly appreciated.
    thanks

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    how are you trying to sort them? more info

  3. #3
    by existing titles in column C.
    e.g. apple, orange, grapes, banana, etc.

  4. #4
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    Quote Originally Posted by preseb
    by existing titles in column C.
    e.g. apple, orange, grapes, banana, etc.
    [VBA]
    'SET i = Worksheet number/title

    ActiveWorkbook.Worksheets(i).Sort.SortFields.Clear
    ActiveWorkbook.Worksheets(i).Sort.SortFields.Add Key:=Range("C1"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets(i).Sort
    .SetRange Range("A:AF")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With

    ActiveWorkbook.Worksheets(i).Sort.SortFields.Clear
    ActiveWorkbook.Worksheets(i).Sort.SortFields.Add Key:=Range("D1"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets(i).Sort
    .SetRange Range("A:AF")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    [/VBA]

    sort column c first, then column d and c will remain sorted, but will rearrange by the d value

  5. #5
    Catdaddy, thanks for those details, but I don;t think it is going to do what I am trying.
    I need to select in Column D all of the M's then say sort that range by Banana, Apple, Orange, Grapes.
    Then find the P range and sort by the same custom listing: Banana, Apple, Orange, Grapes.
    and again for Grouped

    Thanks
    Apple M
    Orange M
    Grapes M
    Banana M
    Apple P
    Orange P
    Grapes P
    Banana P
    Apple Grouped
    Orange Grouped
    Grapes Grouped
    Banana Grouped

  6. #6
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    are you trying to send these to separate worksheets or something? this should group them the way you want, or if you need a custom order you can change the "Order"

  7. #7
    That worked perfectly - thank you

  8. #8
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    Quote Originally Posted by preseb
    That worked perfectly - thank you
    mark it as solved homie!

Posting Permissions

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