+ Reply to Thread
Results 1 to 21 of 21

custom sort according to header in each sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-25-2014
    Location
    India
    MS-Off Ver
    Excel pro plus 2021
    Posts
    186

    Re: custom sort according to header in each sheet

    please check SHEET2.jpg
    Last edited by raj soni; 11-28-2014 at 01:44 PM.

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

    Re: custom sort according to header in each sheet

    Are you saying that you would like the number in column "E" that relates to the Unique row of data in the same row, columns "A to D", to be placed against the same Combinations after the sort.

  3. #3
    Forum Contributor
    Join Date
    04-25-2014
    Location
    India
    MS-Off Ver
    Excel pro plus 2021
    Posts
    186

    Re: custom sort according to header in each sheet

    yes sir

    exactly ,

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

    Re: custom sort according to header in each sheet

    Try this:-
    Its a bit slow approx 30Secs, if too slow, I'll rewrite using arrays ???
    Sub MG29Nov00
    'Range Code
    Dim Rng As Range, n As Long, nn As Long
    Dim Dn As Range, c As Long, Stg As String
    Dim RngAc As Range, Ac As Range
    Dim Dic As Object, Q As Variant
    Dim Shts As Variant, Sh As Variant, G As Variant
    Dim nDic As Object
    Dim t
    t = Timer
    Shts = Array(1, 2, 3, 4)
    For Each Sh In Shts
       Set Dic = CreateObject("Scripting.Dictionary")
           Dic.CompareMode = 1
           Set RngAc = Sheets("Order").Range("A1:D1")
            For Each Ac In RngAc
                If Not Dic.Exists(Ac.Value) Then
                    Set Dic(Ac.Value) = CreateObject("Scripting.Dictionary")
                End If
                With Sheets("Order")
                    Set Rng = .Range(.Cells(Ac.Offset(1).Row, Ac.Column), .Cells(Rows.Count, Ac.Column).End(xlUp))
                End With
                For Each Dn In Rng
                    If Not Dic(Ac.Value).Exists(Dn.Value) Then Dic(Ac.Value).Add (Dn.Value), 0
                Next Dn
            Next Ac
    
        Set RngAc = Sheets(Sh).Range("A1:D1")
        Set nDic = CreateObject("Scripting.Dictionary")
           nDic.CompareMode = 1
          'Ref#
      With Sheets(Sh)
            Set Rng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
        End With
            For Each Dn In Rng
                With Application
                    Stg = Join(.Transpose(.Transpose(Dn.Resize(, 4).Value)))
                End With
                nDic.Item(Stg) = Dn.Offset(, 4)
           
    
           Next Dn
        'Ref#
    For Each Ac In RngAc
           With Sheets(Sh)
            Set Rng = .Range(.Cells(Ac.Offset(1).Row, Ac.Column), .Cells(Rows.Count, Ac.Column).End(xlUp))
           End With
    
            For Each Dn In Rng
                    If Dic(Ac.Value).Exists(Dn.Value) Then
                    Dic(Ac.Value).Item(Dn.Value) = Dic(Ac.Value).Item(Dn.Value) + 1
                    End If
            Next Dn
    
    c = 1
        For Each G In Dic(Ac.Value)
            For nn = 1 To Dic(Ac.Value).Item(G)
                c = c + 1
                Sheets(Sh).Cells(c, Ac.Column) = G
            Next nn
        Next G
    Next Ac
    'Ref# Add
     With Sheets(Sh)
    Set Rng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
     End With
            For Each Dn In Rng
                With Application
                    Stg = Join(.Transpose(.Transpose(Dn.Resize(, 4).Value)))
                End With
                Dn.Offset(, 4) = nDic.Item(Stg)
           Next Dn
    
    'Ref# Add
    Next Sh
    MsgBox Timer - t
    End Sub
    Regards Mick

  5. #5
    Forum Contributor
    Join Date
    04-25-2014
    Location
    India
    MS-Off Ver
    Excel pro plus 2021
    Posts
    186

    Re: custom sort according to header in each sheet

    sir , thanks for trying , but this one is giving totally different result .
    its copying down data

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

    Re: custom sort according to header in each sheet

    The code that you said was OK is basically the same as the code you say is not OK. The results from both codes, to me seem the same.
    To clarify what you require Please supply an example of you Basic data, and an Example of what you expect to see when the code has run.
    The sample need to be large enough to ensure there is no ambiguity.

  7. #7
    Forum Contributor
    Join Date
    04-25-2014
    Location
    India
    MS-Off Ver
    Excel pro plus 2021
    Posts
    186

    Re: custom sort according to header in each sheet

    hello sir , sorry for trouble.
    don't know why its not working now ,
    i have attach before and after sample file .

    1 ) sheet "order" has values how custom sort order should appear .
    2 ) sheet 1 to 4 has 5 different headers in a1:e1
    3 ) headers in this 4 sheets are placed differently .
    3 ) in every 4 sheets , we have to
    custom sort
    column A first according to its header A1
    then column b according to its header B1,
    then column c according to its header C1
    then column d according to its header D1
    then column e according to its header E1
    according to order we have referenced in ORDER sheet .
    4 ) most interesting part is here , column f has id number ....here we need to expand selection , no need to sort .
    for example i have mark id : 91 .....in all 4 sheets .

    if you check values corresponding to 91 ....all are same but in differently place .
    Earth April Tuesday Red Cucumber 91...............SHEET1
    Red Tuesday Earth April Cucumber 91...............SHEET2
    Tuesday Earth April Cucumber Red 91...............SHEET3
    Cucumber Earth Red Tuesday April 91...............SHEET4

    all values of combination are same , but combination are different

+ 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. VB Code Custom Sort then Insert Header
    By Intalzky in forum Excel General
    Replies: 3
    Last Post: 09-16-2014, 11:06 PM
  2. [SOLVED] How to save a custom header/footer on ea. sheet of a workbook?
    By auditthis in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 PM
  3. [SOLVED] How to save a custom header/footer on ea. sheet of a workbook?
    By auditthis in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 AM
  4. How to save a custom header/footer on ea. sheet of a workbook?
    By auditthis in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. How to save a custom header/footer on ea. sheet of a workbook?
    By auditthis in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM

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