Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to sort variable data range fails Kiwipingu Excel Discussion (Misc queries) 1 June 3rd 10 10:16 PM
Macro to Sort A-Z a variable range of cells Keith B Excel Discussion (Misc queries) 1 September 9th 09 03:31 AM
VBA Variable Range Sort Tony Excel Discussion (Misc queries) 4 April 9th 09 08:21 PM
trim left of a found word in a text variable MervB Excel Programming 6 November 15th 05 10:10 PM
Putting text in a column based on variable text from another colum Jacky D. Excel Discussion (Misc queries) 1 December 16th 04 06:09 PM


All times are GMT +1. The time now is 09:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"