+ Reply to Thread
Results 1 to 2 of 2

Set variable sort range based on found text

Hybrid View

  1. #1
    jeffbert
    Guest

    Set variable sort range based on found text


    I need to sort a worksheet from columns A10:AE, with the last row of the
    sort procedure being two rows above where "XYZ" is found in column A. There
    are blank cells in the range also.

    For example:

    XYZ is in cell A110. I need to sort the using the range A10:AE108

    Any and all help is greatly appreciated.

  2. #2
    Jim Thomlinson
    Guest

    RE: Set variable sort range based on found text

    This should be close... You did not specify how youwanted the data sorted so
    I sorted by column A with no header row. You also did not specify a sheet so
    you will have to change the code to suit...

    Sub SortStuff()
    Dim rngToSort As Range
    Dim rngFound As Range
    Dim wks As Worksheet

    Set wks = Sheets("Sheet1")
    Set rngFound = wks.Columns(1).Find(What:="xyz", _
    LookAt:=xlWhole, _
    LookIn:=xlFormulas, _
    MatchCase:=True)
    If rngFound Is Nothing Then
    MsgBox "Sorry, couldn't find xyz"
    Else
    Set rngToSort = Range("AE10", rngFound.Offset(-2, 0))
    rngToSort.Sort Key1:=Range("A10"), _
    order1:=xlAscending, _
    Header:=xlNo
    End If

    End Sub
    --
    HTH...

    Jim Thomlinson


    "jeffbert" wrote:

    >
    > I need to sort a worksheet from columns A10:AE, with the last row of the
    > sort procedure being two rows above where "XYZ" is found in column A. There
    > are blank cells in the range also.
    >
    > For example:
    >
    > XYZ is in cell A110. I need to sort the using the range A10:AE108
    >
    > Any and all help is greatly appreciated.


+ 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