+ Reply to Thread
Results 1 to 4 of 4

Sorting Data into two different Sets

Hybrid View

  1. #1
    Registered User
    Join Date
    01-04-2014
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    15

    Sorting Data into two different Sets

    I am trying to add a sort to a macro that would separate the data into two different groups. There are columns for date, room, time. I would like to separate into a group the includes rooms A,B,C that is sorted by date, room, time then a group that includes rooms D,E,F that is also sorted by date, room, time.
    Attached Files Attached Files
    Last edited by santanicopandimonium; 08-01-2018 at 10:49 AM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sorting Data into two different Sets

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    The reason is yes, we can help, but something like this usually requires a bit of testing, and you will get much more help if people don't have to go and re-create your data in order to write some code for it. Thanks for understanding.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Sorting Data into two different Sets

    This code should Update Column "A" of Sheet1, "Raw Data".
    Sub MG01Aug10
    Dim Rng As Range, Dn As Range, n As Long, k As Variant, c As Long
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For Each Dn In Rng
        If Not .Exists(Dn.Value) Then
            .Add Dn.Value, Dn
       Else
          Set .Item(Dn.Value) = Union(.Item(Dn.Value), Dn)
        End If
    Next
    For Each k In .keys
       .Item(k).Resize(, 3).Sort .Item(k).Offset(, 2)(1)
    Next k
    
    
    
    ReDim Ray(1 To Rng.Count, 1 To 3)
    For Each Dn In Rng
        If Dn.Offset(, 2) <= "C" Then
            c = c + 1
            Ray(c, 1) = Dn.Value
            Ray(c, 2) = Format(Dn.Offset(, 1).Value, "hh:mm AM/PM")
            Ray(c, 3) = Dn.Offset(, 2).Value
        End If
    Next Dn
    For Each Dn In Rng
        If Dn.Offset(, 2) > "C" Then
            c = c + 1
            Ray(c, 1) = Dn.Value
            Ray(c, 2) = Format(Dn.Offset(, 1).Value, "hh:mm AM/PM")
            Ray(c, 3) = Dn.Offset(, 2).Value
        End If
    Next Dn
    Range("A2").Resize(UBound(Ray, 1), 3).Value = Ray
    End With
    
    End Sub
    Regards Mick

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,597

    Re: Sorting Data into two different Sets

    Try
    Sub test()
        Dim x, a, b, e, n As Long
        n = 1
        With Cells(1).CurrentRegion
            With Cells(1).CurrentRegion.Offset(1).Resize(.Rows.Count - 1)
                x = Filter(Evaluate("transpose(if(isnumber(find(trim(" & _
                .Columns(3).Address & "),""ABC"")),row(1:" & .Rows.Count & ")))"), False, 0)
                If UBound(x) > -1 Then
                    a = Application.Index(.Value, Application.Transpose(x), _
                    Evaluate("column(" & .Rows(1).Address & ")"))
                End If
                x = Filter(Evaluate("transpose(if(iserr(find(trim(" & _
                .Columns(3).Address & "),""ABC"")),row(1:" & .Rows.Count & ")))"), False, 0)
                If UBound(x) > -1 Then
                    b = Application.Index(.Value, Application.Transpose(x), _
                    Evaluate("column(" & .Rows(1).Address & ")"))
                End If
                For Each e In Array(a, b)
                    If IsArray(e) Then
                        With .Rows(n).Resize(UBound(e, 1))
                            .Value = e
                            .Sort .Cells(1, 1), , .Cells(1, 3)
                            n = n + UBound(e, 1)
                        End With
                    End If
                Next
            End With
        End With
    End Sub
    Last edited by jindon; 08-01-2018 at 12:26 PM. Reason: Code replaced, Added error trap.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How To Compare Two Sets Of Similar Data Sets To Find a Good Match
    By Mark123456789 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2016, 01:29 AM
  2. Excel sorting 2 sets of data and matching them.
    By trosh in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-19-2016, 07:00 AM
  3. [SOLVED] Macro sorting multiple sets of columns
    By Roger1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-12-2015, 06:46 PM
  4. [SOLVED] Sorting two data sets on Cluster chart
    By inq80 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 09-15-2015, 09:23 AM
  5. Conditional Formatting Rows, and Matching and Sorting Two Sets of Data
    By Alan L 185 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-07-2013, 08:16 PM
  6. VBA: sorting sets of data
    By Grocson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2013, 12:27 AM
  7. sorting different sets of data
    By Armageddon85 in forum Excel General
    Replies: 4
    Last Post: 02-05-2008, 04:37 PM

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