+ Reply to Thread
Results 1 to 4 of 4

Function to sort data in Excel dynamically

Hybrid View

  1. #1
    Registered User
    Join Date
    11-11-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    3

    Function to sort data in Excel dynamically

    Hi

    Is there anybody who knows where I can find a function which will sort a range dynamically? Right now I'm using the rank-function and vlookup to do this, but I would love to have a specific function (VBA) which can do it.

    Do anybody know if somebody have made this? I have found this one, but I would prefer if it wasn't arrays.

    Regards
    Herby

  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Function to sort data in Excel dynamically

    What do you mean? You can click the sort button on the tool bar, and that will sort alphabetically.

  3. #3
    Registered User
    Join Date
    11-11-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Function to sort data in Excel dynamically

    Yes. But not dynamically. If I change data, the sorted range does not update automatically.

    I need to be able to add a function like "sortfunction("$A$1:$A$10")" in "C1:C10" where "C1:C10" will be the sorted data from "A1:A10".

  4. #4
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Function to sort data in Excel dynamically

    You might try something like this:

    Sub SortA4C()
        Dim i As Long, j As Long, v As Variant, vArray() As Variant
        'Copy Range to Array
        vArray = Range("$A$1:$A$10")
        'Bubble Sort Array
        For i = LBound(vArray) To UBound(vArray) - 1
            For j = i + 1 To UBound(vArray)
                If vArray(i, 1) > vArray(j, 1) Then
                    v = vArray(j, 1)
                    vArray(j, 1) = vArray(i, 1)
                    vArray(i, 1) = v
                End If
            Next j
        Next i
        'Copy Array to Range
        Range("$C$1:$C$10") = vArray
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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