I wrote a VBA Code to insert specific numbers of my office-related stuff into another Excel sheet which puts them together and calculates cost relevant stuff.
Now I want to sort my "office numbers" which look like this "1.2.30", "1.1.1130" or "1.3.150" in a row from left to right. To sort I have to change them, the question is how to do this?
Also in the columns there are other numbers I want to switch with the "office numbers" in the header row.
Example
Sorting this:
1.2.30 1.1.1130 1.3.150
1 4 7
2 5 8
3 6 9
To this:
1.1.1130 1.2.30 1.3.150
4 1 7
5 2 8
6 3 9
Excel would sort it like this: 1.2.30, 1.3.150, 1.1.1130
I have to find a way to change those numbers into normal numbers (which I already did by excluding those ".") and to save them as a string after the last point and adding as many "0" so I have standardized numbers with 5 numbers long I guess?
So all my office numbers after the last point looks like this: 1.2.30 = (1.2.)00030, 1.3.150 = (1.3.)150 = 00150 and 1.1.1130 = (1.1.)01130
Code to sort I tried so far:
Sub Table1Sort()
Range("B39:Q39").Select
Selection.ClearContents
Range("B44:Q44").Select
Selection.ClearContents
Range("B9:Q28").Select
ActiveWorkbook.Worksheets("Table1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Table1").Sort.SortFields.Add2 Key:=Range( _
"B10:Q10"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Table1").Sort
.SetRange Range("B9:Q28")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Dim rng As Range
For Each rng In Range("B9:Q9")
rng = rng
Next
End Sub
Saving the numbers as strings and adding zeros maybe? Or maybe my logic is all wrong?