+ Reply to Thread
Results 1 to 2 of 2

Sorts on variable ranges

  1. #1
    bman342
    Guest

    Sorts on variable ranges

    I have data being imported to a spreadsheet that needs to be sorted.
    The range of data elements is inconsistent.
    I want to automate the sort function.
    I recorded a macro that highlights the first data element, which will always
    be consistent (say at: A4), and then moves down to a cell that defines a
    range that I know will always be larger than the amount of data elements
    being imported (say A300). But if I do an alphabetical sort, the blank cells
    will be placed first.

    If there a way to automatically highlight just the range of data elements,
    and then do the sort?

    Thanks.

  2. #2
    JonR
    Guest

    RE: Sorts on variable ranges

    This will work with varying data table lengths as long as there are no blank
    cells in between data elements (i.e. you can't have data down to A255 if
    there is a blank in A75 -- it will go to A74 and stop)


    Sub sort()

    Dim inRow

    Cells(4, 1).Select

    inRow = Selection.End(xlDown).Row

    Range(Cells(4, 1), Cells(inRow, 1)).SortSpecial

    End Sub

    HTH
    JonR

    "bman342" wrote:

    > I have data being imported to a spreadsheet that needs to be sorted.
    > The range of data elements is inconsistent.
    > I want to automate the sort function.
    > I recorded a macro that highlights the first data element, which will always
    > be consistent (say at: A4), and then moves down to a cell that defines a
    > range that I know will always be larger than the amount of data elements
    > being imported (say A300). But if I do an alphabetical sort, the blank cells
    > will be placed first.
    >
    > If there a way to automatically highlight just the range of data elements,
    > and then do the sort?
    >
    > Thanks.


+ 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