+ Reply to Thread
Results 1 to 12 of 12

Sorting numbers with multiple decimal points?

  1. #1
    Jonathan
    Guest

    Sorting numbers with multiple decimal points?

    Hi - I'm sure this is covered in some docs somewhere, but it's hard to
    know what to search for.

    I have a spreadsheet (using Excel 2003 SP1) in which I have a number of
    rows that have an "ID" field taking the format "X.X.X.X" where X is a
    number from 0 to 100. Like this:

    1.1.0.0 blah blah rest of row
    1.1.2.4 blah blah rest of row
    1.1.3.0 blah blah rest of row
    1.0.0.0 blah blah rest of row
    1.1.3.2 blah blah rest of row
    1.1.3.1 blah blah rest of row
    1.1.1.1 blah blah rest of row
    1.1.3.0 blah blah rest of row
    1.1.1.3 blah blah rest of row
    1.1.2.5 blah blah rest of row
    1.1.1.2 blah blah rest of row
    .... Etc.

    How can I sort these rows so they look like this (i.e. in numerical
    order by ID number):

    1.0.0.0 blah blah rest of row
    1.1.0.0 blah blah rest of row
    1.1.1.1 blah blah rest of row
    1.1.1.2 blah blah rest of row
    1.1.1.3 blah blah rest of row
    1.1.2.4 blah blah rest of row
    1.1.2.5 blah blah rest of row
    1.1.3.0 blah blah rest of row
    1.1.3.1 blah blah rest of row
    1.1.3.2 blah blah rest of row

    Thanks for any tips!

    Jonathan

  2. #2
    Forum Contributor
    Join Date
    04-11-2005
    Location
    London
    Posts
    259
    Hi Jonathon

    Place your cursor in the top left cell and select the entire table. Now click on the A-Z icon at the top of the screen.
    Last edited by MartinShort; 05-17-2005 at 05:02 AM.
    Martin Short

  3. #3
    Mangesh Yadav
    Guest

    Re: Sorting numbers with multiple decimal points?

    You can directly sort it goign to Data > Sort

    Mangesh


    "Jonathan" <sorry@this_is_fake.com> wrote in message
    news:[email protected]...
    > Hi - I'm sure this is covered in some docs somewhere, but it's hard to
    > know what to search for.
    >
    > I have a spreadsheet (using Excel 2003 SP1) in which I have a number of
    > rows that have an "ID" field taking the format "X.X.X.X" where X is a
    > number from 0 to 100. Like this:
    >
    > 1.1.0.0 blah blah rest of row
    > 1.1.2.4 blah blah rest of row
    > 1.1.3.0 blah blah rest of row
    > 1.0.0.0 blah blah rest of row
    > 1.1.3.2 blah blah rest of row
    > 1.1.3.1 blah blah rest of row
    > 1.1.1.1 blah blah rest of row
    > 1.1.3.0 blah blah rest of row
    > 1.1.1.3 blah blah rest of row
    > 1.1.2.5 blah blah rest of row
    > 1.1.1.2 blah blah rest of row
    > ... Etc.
    >
    > How can I sort these rows so they look like this (i.e. in numerical
    > order by ID number):
    >
    > 1.0.0.0 blah blah rest of row
    > 1.1.0.0 blah blah rest of row
    > 1.1.1.1 blah blah rest of row
    > 1.1.1.2 blah blah rest of row
    > 1.1.1.3 blah blah rest of row
    > 1.1.2.4 blah blah rest of row
    > 1.1.2.5 blah blah rest of row
    > 1.1.3.0 blah blah rest of row
    > 1.1.3.1 blah blah rest of row
    > 1.1.3.2 blah blah rest of row
    >
    > Thanks for any tips!
    >
    > Jonathan




  4. #4
    Tom Ogilvy
    Guest

    Re: Sorting numbers with multiple decimal points?

    For the numbers you show, they sort that way now. The only place where I
    would see a problem is when you get to numbers like

    1.1.10.1

    In that case, you need to copy the column to the far right, then on that
    copy of the data do Text to Columns; select delimited, then select period
    as the delimiter. Now sort the last 3 columns (the far right columns of the
    new columns), then sort again on the first column of the new column (you
    have to sort a max of 3 columns at a time. Excel's sort is
    stable/persistent, so you can progress from least important to most
    important using multiple sorts to sort on more than 3 columns).

    --
    Regards,
    Tom Ogilvy

    "Jonathan" <sorry@this_is_fake.com> wrote in message
    news:[email protected]...
    > Hi - I'm sure this is covered in some docs somewhere, but it's hard to
    > know what to search for.
    >
    > I have a spreadsheet (using Excel 2003 SP1) in which I have a number of
    > rows that have an "ID" field taking the format "X.X.X.X" where X is a
    > number from 0 to 100. Like this:
    >
    > 1.1.0.0 blah blah rest of row
    > 1.1.2.4 blah blah rest of row
    > 1.1.3.0 blah blah rest of row
    > 1.0.0.0 blah blah rest of row
    > 1.1.3.2 blah blah rest of row
    > 1.1.3.1 blah blah rest of row
    > 1.1.1.1 blah blah rest of row
    > 1.1.3.0 blah blah rest of row
    > 1.1.1.3 blah blah rest of row
    > 1.1.2.5 blah blah rest of row
    > 1.1.1.2 blah blah rest of row
    > ... Etc.
    >
    > How can I sort these rows so they look like this (i.e. in numerical
    > order by ID number):
    >
    > 1.0.0.0 blah blah rest of row
    > 1.1.0.0 blah blah rest of row
    > 1.1.1.1 blah blah rest of row
    > 1.1.1.2 blah blah rest of row
    > 1.1.1.3 blah blah rest of row
    > 1.1.2.4 blah blah rest of row
    > 1.1.2.5 blah blah rest of row
    > 1.1.3.0 blah blah rest of row
    > 1.1.3.1 blah blah rest of row
    > 1.1.3.2 blah blah rest of row
    >
    > Thanks for any tips!
    >
    > Jonathan




  5. #5
    Jonathan
    Guest

    Re: Sorting numbers with multiple decimal points?

    Tom Ogilvy wrote:
    > For the numbers you show, they sort that way now. The only place where I
    > would see a problem is when you get to numbers like
    >
    > 1.1.10.1
    >
    > In that case, you need to copy the column to the far right, then on that
    > copy of the data do Text to Columns; select delimited, then select period
    > as the delimiter. Now sort the last 3 columns (the far right columns of the
    > new columns), then sort again on the first column of the new column (you
    > have to sort a max of 3 columns at a time. Excel's sort is
    > stable/persistent, so you can progress from least important to most
    > important using multiple sorts to sort on more than 3 columns).
    >


    Thanks - I'll give that a try. If not I think I can use GNU sort with
    cut, but it'll mean exporting/importing though.


  6. #6
    Ron Rosenfeld
    Guest

    Re: Sorting numbers with multiple decimal points?

    On Fri, 13 May 2005 12:20:10 +0100, Jonathan <sorry@this_is_fake.com> wrote:

    >Hi - I'm sure this is covered in some docs somewhere, but it's hard to
    >know what to search for.
    >
    >I have a spreadsheet (using Excel 2003 SP1) in which I have a number of
    >rows that have an "ID" field taking the format "X.X.X.X" where X is a
    >number from 0 to 100. Like this:
    >
    >1.1.0.0 blah blah rest of row
    >1.1.2.4 blah blah rest of row
    >1.1.3.0 blah blah rest of row
    >1.0.0.0 blah blah rest of row
    >1.1.3.2 blah blah rest of row
    >1.1.3.1 blah blah rest of row
    >1.1.1.1 blah blah rest of row
    >1.1.3.0 blah blah rest of row
    >1.1.1.3 blah blah rest of row
    >1.1.2.5 blah blah rest of row
    >1.1.1.2 blah blah rest of row
    >... Etc.
    >


    Are these IP addresses?
    --ron

  7. #7
    Jonathan
    Guest

    Re: Sorting numbers with multiple decimal points?

    Ron Rosenfeld wrote:
    > On Fri, 13 May 2005 12:20:10 +0100, Jonathan <sorry@this_is_fake.com> wrote:
    >
    >
    >>Hi - I'm sure this is covered in some docs somewhere, but it's hard to
    >>know what to search for.
    >>
    >>I have a spreadsheet (using Excel 2003 SP1) in which I have a number of
    >>rows that have an "ID" field taking the format "X.X.X.X" where X is a
    >>number from 0 to 100. Like this:
    >>
    >>1.1.0.0 blah blah rest of row
    >>1.1.2.4 blah blah rest of row
    >>1.1.3.0 blah blah rest of row
    >>1.0.0.0 blah blah rest of row
    >>1.1.3.2 blah blah rest of row
    >>1.1.3.1 blah blah rest of row
    >>1.1.1.1 blah blah rest of row
    >>1.1.3.0 blah blah rest of row
    >>1.1.1.3 blah blah rest of row
    >>1.1.2.5 blah blah rest of row
    >>1.1.1.2 blah blah rest of row
    >>... Etc.
    >>

    >
    >
    > Are these IP addresses?
    > --ron


    No - they're ID numbers.


  8. #8
    Ron Rosenfeld
    Guest

    Re: Sorting numbers with multiple decimal points?

    On Mon, 16 May 2005 11:10:32 +0100, Jonathan <sorry@this_is_fake.com> wrote:


    >
    >No - they're ID numbers.


    I would add an adjacent helper column that is the ID column converted to "real"
    numbers; then sort on that and delete the helper column.

    Probably best done using a macro, although you could devise a worksheet formula
    that would do the conversion.

    Something like this macro might give you some ideas. You might have to make
    some changes depending on your worksheet layout. The macro assumes the columns
    are sorted; and that the range with ID numbers is Named "ID".

    ============================
    Sub SortID()
    Range("ID").Insert xlShiftToRight
    MakeNum Range("ID")

    Range("ID").CurrentRegion.Sort Key1:=Range("ID").Offset(0, -1), _
    Order1:=xlAscending, Header:=xlYes, _
    MatchCase:=False, Orientation:=xlTopToBottom

    Range("ID").Offset(0, -1).Delete xlShiftToLeft

    End Sub
    '--------------------------------------------
    Sub MakeNum(rg As Range)
    Dim i As Long
    Dim c As Range
    Dim N
    Dim num

    For Each c In rg
    num = ""
    N = Split(c.Text, ".")

    If UBound(N) = 3 Then
    For i = 0 To 3
    num = num & Right("0" & N(i), 2)
    Next i
    Else: num = N
    End If

    c.Offset(0, -1).Value = num
    Next c

    End Sub
    ==============================


    --ron

  9. #9
    Jonathan
    Guest

    Re: Sorting numbers with multiple decimal points?

    Ron Rosenfeld wrote:
    > On Mon, 16 May 2005 11:10:32 +0100, Jonathan <sorry@this_is_fake.com> wrote:
    >
    >
    >
    >>No - they're ID numbers.

    >
    >
    > I would add an adjacent helper column that is the ID column converted to "real"
    > numbers; then sort on that and delete the helper column.
    >
    > Probably best done using a macro, although you could devise a worksheet formula
    > that would do the conversion.
    >
    > Something like this macro might give you some ideas. You might have to make
    > some changes depending on your worksheet layout. The macro assumes the columns
    > are sorted; and that the range with ID numbers is Named "ID".
    >
    > ============================
    > Sub SortID()
    > Range("ID").Insert xlShiftToRight
    > MakeNum Range("ID")
    >
    > Range("ID").CurrentRegion.Sort Key1:=Range("ID").Offset(0, -1), _
    > Order1:=xlAscending, Header:=xlYes, _
    > MatchCase:=False, Orientation:=xlTopToBottom
    >
    > Range("ID").Offset(0, -1).Delete xlShiftToLeft
    >
    > End Sub
    > '--------------------------------------------
    > Sub MakeNum(rg As Range)
    > Dim i As Long
    > Dim c As Range
    > Dim N
    > Dim num
    >
    > For Each c In rg
    > num = ""
    > N = Split(c.Text, ".")
    >
    > If UBound(N) = 3 Then
    > For i = 0 To 3
    > num = num & Right("0" & N(i), 2)
    > Next i
    > Else: num = N
    > End If
    >
    > c.Offset(0, -1).Value = num
    > Next c
    >
    > End Sub
    > ==============================
    >
    >



    Hey thanks Ron, that looks just what I'm looking for!




  10. #10
    Ron Rosenfeld
    Guest

    Re: Sorting numbers with multiple decimal points?

    On Tue, 17 May 2005 00:29:04 +0100, Jonathan <sorry@this_is_fake.com> wrote:

    >Hey thanks Ron, that looks just what I'm looking for!


    You're welcome. I hope it works out for you.

    --ron

  11. #11
    Ron Rosenfeld
    Guest

    Re: Sorting numbers with multiple decimal points?

    On Tue, 17 May 2005 00:29:04 +0100, Jonathan <sorry@this_is_fake.com> wrote:

    >Hey thanks Ron, that looks just what I'm looking for!


    Jonathan,

    mea culpa.

    When I was writing the macro, I was misremembering what you had wrote.

    The macro as written will only handle 0<=X<=99.

    If X can equal 100, you need to make a small change:

    > For i = 0 To 3

    --------->> num = num & Right("00" & N(i), 3)
    > Next i



    --ron

  12. #12
    Jonathan
    Guest

    Re: Sorting numbers with multiple decimal points?

    Ron Rosenfeld wrote:
    > On Tue, 17 May 2005 00:29:04 +0100, Jonathan <sorry@this_is_fake.com> wrote:
    >
    >
    >>Hey thanks Ron, that looks just what I'm looking for!

    >
    >
    > Jonathan,
    >
    > mea culpa.
    >
    > When I was writing the macro, I was misremembering what you had wrote.
    >
    > The macro as written will only handle 0<=X<=99.
    >
    > If X can equal 100, you need to make a small change:
    >
    >
    >> For i = 0 To 3

    >
    > --------->> num = num & Right("00" & N(i), 3)
    >
    >> Next i



    Ah - good, got it, thanks again!



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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