how to sort small to big horizontally

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
510
Office Version
  1. 365
Platform
  1. Windows
hi, i'm using this function with the udf below,
the problem is that it doesnt sorting the number small to big,
can you help me please?

test
CDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1123456
2123453611112151622223336373844056789
32311151637
4389121538
5678222340 
test
Cell Formulas
RangeFormula
K2:AC2K2=INDEX(SORT(UNIQUES(C2:H5)),SEQUENCE(,COUNTA(UNIQUES(C2:H5))))
K5K5=INDEX(SORT(UNIQUES(C6:H9)),SEQUENCE(,COUNTA(UNIQUES(C6:H9))))
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:H5Cell ValueduplicatestextNO
I1:I5Cell Value>4textNO
I1:J5Cell Value=6textNO



VBA Code:
Function UNIQUES(rng As Range) As Variant()
Dim list As New Collection
Dim Ulist() As Variant

'Adding each value of rng to the collection.
On Error Resume Next
For Each Value In rng
    'here value and key are the same. The collection does not allow duplicate keys hence only unique values will remain.
    list.Add CStr(Value), CStr(Value)
Next
On Error GoTo 0

'Defining the length of the array to the number of unique values. Since the array starts from 0, we subtract 1.
ReDim Ulist(list.Count - 1, 0)

'Adding unique value to the array.
For i = 0 To list.Count - 1
    Ulist(i, 0) = list(i + 1)
Next

'Printing the array
UNIQUES = Ulist
End Function
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Does this do what you are looking for?

COMPSTAT Template.xltx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1123456
2123453612345678911121516222336373840
32311151637
4389121538
5678222340
Data
Cell Formulas
RangeFormula
H2:Z2H2=LET(t,A2:F5,r,ROWS(t),s,SEQUENCE(r*COLUMNS(t),,0),rs,MOD(s,r)+1,cs,INT(s/r)+1,i,INDEX(t,rs,cs),TRANSPOSE(UNIQUE(SORT(i))))
Dynamic array formulas.
 
Upvote 0
Solution
Just for fun, here's how I would do it just using the UDF.

COMPSTAT Template.xltx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1123456
2123453612345678911121516222336373840
32311151637
4389121538
5678222340
Data
Cell Formulas
RangeFormula
H2:Z2H2=hus(A2:F5)
Dynamic array formulas.


VBA Code:
Function HUS(r As Range)
Dim AR() As Variant:        AR = r.Value2

With CreateObject("System.Collections.ArrayList")
    For Each itm In AR
        If Not .Contains(itm) Then .Add (itm)
    Next itm
    .Sort
    HUS = .toArray
End With
End Function
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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