Sort and arrange file names from smallest to largest

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hello. Look for an icon that enables me to sort file links on column B From the smallest to the largest, if you notice the second row with the number 10, it is supposed to be 2 and so on to the end of the column in order
Capture.PNG
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Yep, that is because you have text entries and are therefore sorting alphabetically, not numerically.

So everything that starts out with:
5may\11-data\1
will come before any entries that starts:
5may\11-data\2
The best way to get it to sort the way you want is to change the format so that all those numbers have the same number of digits (i.e. 2),
so your single digit entries should be changed like this:
5may\11-data\01

5may\11-data\02

Then it is very easy to sort exactly the way you want.
 
Upvote 0
Yep, that is because you have text entries and are therefore sorting alphabetically, not numerically.

So everything that starts out with:
5may\11-data\1
will come before any entries that starts:
5may\11-data\2
The best way to get it to sort the way you want is to change the format so that all those numbers have the same number of digits (i.e. 2),
so your single digit entries should be changed like this:
5may\11-data\01

5may\11-data\02

Then it is very easy to sort exactly the way you want.
Thank you for the reply.I replaced you manually and copied it into another sheet and recorded a macro for clarification.I lack to return it to sheet 1 starting from cell B12
1.PNG
2.PNG



VBA Code:
   Sheet1.Activate
    Range("B12").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("sumrec").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :="\", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
        TrailingMinusNumbers:=True
    ActiveWindow.SmallScroll Down:=-33
    Columns("A:D").Select
    ActiveWorkbook.Worksheets("sumrec").Sort.SortFields.clear
    ActiveWorkbook.Worksheets("sumrec").Sort.SortFields.Add2 Key:=Range("B1:B1000" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("sumrec").Sort.SortFields.Add2 Key:=Range("C1:C1000" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("sumrec").Sort
        .SetRange Range("A1:D1000")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
Upvote 0
Thank you for the reply.I replaced you manually and copied it into another sheet and recorded a macro for clarification.I lack to return it to sheet 1 starting from cell B12
View attachment 93210


VBA Code:
   Sheet1.Activate
    Range("B12").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("sumrec").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :="\", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
        TrailingMinusNumbers:=True
    ActiveWindow.SmallScroll Down:=-33
    Columns("A:D").Select
    ActiveWorkbook.Worksheets("sumrec").Sort.SortFields.clear
    ActiveWorkbook.Worksheets("sumrec").Sort.SortFields.Add2 Key:=Range("B1:B1000" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("sumrec").Sort.SortFields.Add2 Key:=Range("C1:C1000" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("sumrec").Sort
        .SetRange Range("A1:D1000")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
I am not really sure what you are showing/asking me here.

What I am suggesting is changing the naming convention of your folders from:
Rich (BB code):
1
2
3
4
5
6
7
8
9
10
11
...
to
Rich (BB code):
01
02
03
04
05
06
07
08
09
10
11
...

Then sorting will work the way you want naturally.
 
Upvote 0
Solution
I am not really sure what you are showing/asking me here.

What I am suggesting is changing the naming convention of your folders from:
Rich (BB code):
1
2
3
4
5
6
7
8
9
10
11
...
to
Rich (BB code):
01
02
03
04
05
06
07
08
09
10
11
...

Then sorting will work the way you want naturally.
Thank you again. I'll really try that.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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