Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Probably too easy...change range to be one row down.

I use a cell.find command to find a row col with a certain item. Now
I want to alter that so that its one row below after the find. Here
is what I have so far:

Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range

Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)

' need to set FirstCell to be one row lower to sort the data

Set LastCell = ActiveSheet.Range("E65536").End(xlUp) ' end of data
lines will be in E column
Set SortRange = ActiveSheet.Range(FirstCell, LastCell)
' ActiveSheet.SortRange.Sort ' use A column as key

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Probably too easy...change range to be one row down.

I'd try:

Set SortRange = ActiveSheet.Range(FirstCell.offset(1,0), LastCell)

RocketMan wrote:

I use a cell.find command to find a row col with a certain item. Now
I want to alter that so that its one row below after the find. Here
is what I have so far:

Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range

Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)

' need to set FirstCell to be one row lower to sort the data

Set LastCell = ActiveSheet.Range("E65536").End(xlUp) ' end of data
lines will be in E column
Set SortRange = ActiveSheet.Range(FirstCell, LastCell)
' ActiveSheet.SortRange.Sort ' use A column as key


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Probably too easy...change range to be one row down.

After the Find statement:

FirstCell = FirstCell.Offset(1, 0).Address

Then to get your sort range:

Set LastCell = ActiveSheet.Range("E65536").End(xlUp).Address

SortRange = Range(Firstcell & ":" & LastCell)

"RocketMan" wrote:

I use a cell.find command to find a row col with a certain item. Now
I want to alter that so that its one row below after the find. Here
is what I have so far:

Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range

Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)

' need to set FirstCell to be one row lower to sort the data

Set LastCell = ActiveSheet.Range("E65536").End(xlUp) ' end of data
lines will be in E column
Set SortRange = ActiveSheet.Range(FirstCell, LastCell)
' ActiveSheet.SortRange.Sort ' use A column as key


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Probably too easy...change range to be one row down.

That should be Set SortRange = Range(FirstCell & ":" & LastCell)
And it wouldn't hurt to insert the worksheet name in the Set statement.

"RocketMan" wrote:

I use a cell.find command to find a row col with a certain item. Now
I want to alter that so that its one row below after the find. Here
is what I have so far:

Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range

Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)

' need to set FirstCell to be one row lower to sort the data

Set LastCell = ActiveSheet.Range("E65536").End(xlUp) ' end of data
lines will be in E column
Set SortRange = ActiveSheet.Range(FirstCell, LastCell)
' ActiveSheet.SortRange.Sort ' use A column as key


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Probably too easy...change range to be one row down.

Not quite.
FirstCell = FirstCell.Offset(1, 0).Address
will set the value to the offset address. So "pills" becomes $A$21.

:)


On Jan 30, 8:48*am, JLGWhiz wrote:
After the Find statement:

FirstCell = FirstCell.Offset(1, 0).Address

Then to get your sort range:

Set LastCell = ActiveSheet.Range("E65536").End(xlUp).Address

SortRange = Range(Firstcell & ":" & LastCell)



"RocketMan" wrote:
I use a cell.find command to find a row col with a certain item. *Now
I want to alter that so that its one row below after the find. *Here
is what I have so far:


Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range


Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
* * * * :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
* * * * False)


' need to set FirstCell to be one row lower to sort the data


Set LastCell = ActiveSheet.Range("E65536").End(xlUp) ' end of data
lines will be in E column
Set SortRange = ActiveSheet.Range(FirstCell, LastCell)
' ActiveSheet.SortRange.Sort ' use A column as key- Hide quoted text -


- Show quoted text -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Probably too easy...change range to be one row down.

final code that works...just for reference:

Sub Alpha_Click()

Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range

Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)

Set LastCell = ActiveSheet.Range("A65536").End(xlUp)
Set SortRange = Range(FirstCell.Offset(1, 0), LastCell.Offset(0, 5))
SortRange.Sort Key1:=FirstCell

End Sub
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Probably too easy...change range to be one row down.

Did you not say you wanted the sort range to start one row lower than the
find cell?
If so, then Offset(1, 0) is one row lower. If you want "pills" included in
the sort range, the just use the FirstRow.Address as the front end of the
range. Or give a better explanation of what you mean by one row down.

"RocketMan" wrote:

Not quite.
FirstCell = FirstCell.Offset(1, 0).Address
will set the value to the offset address. So "pills" becomes $A$21.

:)


On Jan 30, 8:48 am, JLGWhiz wrote:
After the Find statement:

FirstCell = FirstCell.Offset(1, 0).Address

Then to get your sort range:

Set LastCell = ActiveSheet.Range("E65536").End(xlUp).Address

SortRange = Range(Firstcell & ":" & LastCell)



"RocketMan" wrote:
I use a cell.find command to find a row col with a certain item. Now
I want to alter that so that its one row below after the find. Here
is what I have so far:


Dim FirstCell As Range
Dim LastCell As Range
Dim SortRange As Range


Set FirstCell = ActiveSheet.Cells.Find(What:="Pills", After:=[A4],
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)


' need to set FirstCell to be one row lower to sort the data


Set LastCell = ActiveSheet.Range("E65536").End(xlUp) ' end of data
lines will be in E column
Set SortRange = ActiveSheet.Range(FirstCell, LastCell)
' ActiveSheet.SortRange.Sort ' use A column as key- Hide quoted text -


- Show quoted text -



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
Question about RANGE (easy one, or at least it should be) Gary Keramidas Excel Programming 2 December 19th 06 07:20 PM
Question about RANGE (easy one, or at least it should be) Don Guillett Excel Programming 1 December 19th 06 04:07 PM
change colorIndex, help me write an easy macro Matt_70501 Excel Programming 4 May 28th 06 07:38 PM
easy way to change a formula fastballfreddy Excel Discussion (Misc queries) 3 May 3rd 06 08:24 AM
Easy question - If ...then Change cell value Mike R. Excel Programming 3 July 30th 05 04:50 AM


All times are GMT +1. The time now is 12:52 PM.

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

About Us

"It's about Microsoft Excel"