Excel Formula to Generate Unique Sorted List

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,549
Office Version
  1. 2016
Platform
  1. Windows
Dear All,

Hope you all are doing well
Please have a look at the sheet & let me know whether is it possible to achieve with formulas (I am using excel 2016)

The purpose is to have Unique Sorted Values in ascending order → By Column B, then by Column A, then By Column C with custom sort list as Set(s), Pc(s), Pair(s) & Dozen(s)

Book1
ABC
1ARTICLEQUALITYUNIT
2BlanketPolyester 125 GSMDozen(s)
3BlanketPolyester 125 GSMDozen(s)
4BlanketPolyester 125 GSMSet(s)
5BlanketPolyester 125 GSMSet(s)
6BlanketPolyester 125 GSMPc(s)
7Fitted SheetCVC 90 GSMPair(s)
8Fitted SheetCVC 90 GSMPair(s)
9Fitted SheetCVC 90 GSMSet(s)
10Fitted SheetCVC 90 GSMPc(s)
11
12
13DESIRED RESULT ↓
14ARTICLEQUALITYUNIT
15Fitted SheetCVC 90 GSMSet(s)
16Fitted SheetCVC 90 GSMPc(s)
17Fitted SheetCVC 90 GSMPair(s)
18BlanketPolyester 125 GSMSet(s)
19BlanketPolyester 125 GSMPc(s)
20BlanketPolyester 125 GSMDozen(s)
Sheet3


Regards,

Humayun
 
This will copy data from Sheet3 and give desired result in Supples Wise sheet range ("A15"). Change the ranges and sheet names as required.
VBA Code:
Sub SortRemoveDuplicates()
With Sheets("Supplier Wise").Range("A15")
.CurrentRegion.Clear
Sheets("Sheet3").Range("A1").CurrentRegion.Copy Sheets("Supplier Wise").Range("A15")
.CurrentRegion.Sort Key1:=.Offset(1, 0), Order1:=xlDescending, Key2:=.Offset(1, 1), Order2:=xlDescending, Key3:=.Offset(1, 2), Order3:=xlDescending, Header:=xlYes
.CurrentRegion.RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
End With
End Sub
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi Peter,

Thanks for the reply

Is it possible to generate the list on some other sheet which is within the workbook → sheet name "Supplier Wise" starting from B11
& instead of looking at the Column A for Article, Column B for Quality & Column for Units it should look at the named ranges as "orders_article", "orders_quality" & "orders_unit"

Further, please note that the data I provided was a sample data but the actual data is very huge & I have noticed that the whole data is being copied and then the duplicates are been removed. I don't want this to happen as there is a lot of other things going on at the bottom of the sheet where I want the list to be generated..

Regards,

Humayun
The named ranges reference the source data and not the data that has been copied to remove the duplicates from.

Why do you want to use named ranges?
 
Upvote 0
The named ranges reference the source data and not the data that has been copied to remove the duplicates from.

Why do you want to use named ranges?
Sorry, I did not understand your point
Why shouldn't I used a named range ??
the data is being used on lot of other sheets as well to generate different reports
 
Upvote 0
Sorry, I did not understand your point
Why shouldn't I used a named range ??
the data is being used on lot of other sheets as well to generate different reports
If data with named ranges is copied to another sheet then the copied data does not have any associated named ranges.

This procedure saves the source data into an array, sorts the data and removes the duplicates using your existing named ranges and then reinstates the
oiginal data from the array.

It clears the existing data on the 'Supplier Wise' worksheet before it is replaced with the new data,

Test it on a copy of your data.

VBA Code:
Public Sub subSortRemoveDuplicatesV2()
Dim Ws As Worksheet
Dim arr() As Variant

  ' ***************** Change the sheet name as appropriate. *****************
  Set Ws = Sheets("Sheet3")
  
  arr = Ws.Range("A1").CurrentRegion
        
  With Ws.Range("A1").CurrentRegion
        
    .Sort Key1:=Range("orders_article"), Order1:=xlDescending, _
      Key2:=Range("orders_quality"), Order2:=xlDescending, _
      Key3:=Range("orders_unit"), Order3:=xlDescending, Header:=xlYes
    
    .RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
   
  End With
  
  Sheets("Supplier Wise").Range("B11").CurrentRegion.ClearContents
    
  With Ws.Range("A1").CurrentRegion
    Sheets("Supplier Wise").Range("B11").Resize(.Rows.Count, .Columns.Count).Value = .Value
    .ClearContents
  End With
        
  Ws.Range("A1").Resize(UBound(arr), 3).Value = arr
    
End Sub
 
Upvote 0
This will remove duplicates and then Puts the data In Supplier Wise sheet and sorts the data.
VBA Code:
Sub SortRemoveDuplicates()
Dim Ary, T&
Dim Dic As Object
Ary = Sheets("Sheet3").Range("A1").CurrentRegion
Set Dic = CreateObject("Scripting.Dictionary")
With Dic
For T = 2 To UBound(Ary, 1)
If Not .exists(Ary(T, 1) & Ary(T, 2) & Ary(T, 3)) Then
.Item(Ary(T, 1) & Ary(T, 2) & Ary(T, 3)) = Array(Ary(T, 1), Ary(T, 2), Ary(T, 3))
End If
Next T
End With

With Sheets("Supplier Wise").Range("A15")
.CurrentRegion.Clear
.Resize(1, 3) = Array(Ary(1, 1), Ary(1, 2), Ary(1, 3))
.Offset(1, 0).Resize(Dic.Count, 3) = WorksheetFunction.Index(Dic.items, 0, 0)
.CurrentRegion.Sort Key1:=.Offset(1, 0), Order1:=xlDescending, Key2:=.Offset(1, 1), Order2:=xlDescending, Key3:=.Offset(1, 2), Order3:=xlDescending, Header:=xlYes
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,225,502
Messages
6,185,350
Members
453,287
Latest member
Emeister

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top