Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Determine last row then sort

I'm trying to determine the last row of data, then move up
a number of rows (to avoid sorting formula cells) and then
perform a sort. I'm not sure how to move up x number of
rows and then use that as the ending portion for a sort.
The first part of the macro shows moving up 15 rows to
avoid the formulas. The second part is hardcoding the
range value. Here is what I have so far

Dim shtworksheet As Worksheet
Dim rngData As Range
Set shtworksheet = _
Application.Workbooks("test1.xls").Worksheets("she et1")
'Initialize the variables
Set rngData = shtworksheet.Range("B6").CurrentRegion
'last cell (moves the cellpointer to the lower right
corner of active files active area
Cells.SpecialCells(xlCellTypeLastCell).Select
'Move up fifteen rows
Selection.Offset(-15, 0).Select
'Identify the specific range for sorting
Range("B6:T50").Select
'sort data by purchase date
'Header:=xlYes leaves the first row untouched
'Header:=xlGuess ??
Selection.Sort Key1:=Range("B6"), Order1:=xlAscending,
Header:=xlGuess

Thanks for your help,
Bernice
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Determine last row then sort

Bernice

Dim LastRw as Long

LastRw = Cells.SpecialCells(xlCellTypeLastCell).Offset(-15,0).Row

Range("B6:T" & LastRw).Sort etc...

The LastCell is not always 100% accurate. You may be better off doing
something like this

LastRw = Range("A65536").End(xlUp).Offset(-15,0).Row


--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.


"Bernice" wrote in message
...
I'm trying to determine the last row of data, then move up
a number of rows (to avoid sorting formula cells) and then
perform a sort. I'm not sure how to move up x number of
rows and then use that as the ending portion for a sort.
The first part of the macro shows moving up 15 rows to
avoid the formulas. The second part is hardcoding the
range value. Here is what I have so far

Dim shtworksheet As Worksheet
Dim rngData As Range
Set shtworksheet = _
Application.Workbooks("test1.xls").Worksheets("she et1")
'Initialize the variables
Set rngData = shtworksheet.Range("B6").CurrentRegion
'last cell (moves the cellpointer to the lower right
corner of active files active area
Cells.SpecialCells(xlCellTypeLastCell).Select
'Move up fifteen rows
Selection.Offset(-15, 0).Select
'Identify the specific range for sorting
Range("B6:T50").Select
'sort data by purchase date
'Header:=xlYes leaves the first row untouched
'Header:=xlGuess ??
Selection.Sort Key1:=Range("B6"), Order1:=xlAscending,
Header:=xlGuess

Thanks for your help,
Bernice



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Determine last row then sort

Dick,

Thanks that worked well.

Bernice
-----Original Message-----
Bernice

Dim LastRw as Long

LastRw = Cells.SpecialCells(xlCellTypeLastCell).Offset(-

15,0).Row

Range("B6:T" & LastRw).Sort etc...

The LastCell is not always 100% accurate. You may be

better off doing
something like this

LastRw = Range("A65536").End(xlUp).Offset(-15,0).Row


--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.


"Bernice" wrote in

message
...
I'm trying to determine the last row of data, then move

up
a number of rows (to avoid sorting formula cells) and

then
perform a sort. I'm not sure how to move up x number of
rows and then use that as the ending portion for a sort.
The first part of the macro shows moving up 15 rows to
avoid the formulas. The second part is hardcoding the
range value. Here is what I have so far

Dim shtworksheet As Worksheet
Dim rngData As Range
Set shtworksheet = _
Application.Workbooks("test1.xls").Worksheets

("sheet1")
'Initialize the variables
Set rngData = shtworksheet.Range("B6").CurrentRegion
'last cell (moves the cellpointer to the lower right
corner of active files active area
Cells.SpecialCells(xlCellTypeLastCell).Select
'Move up fifteen rows
Selection.Offset(-15, 0).Select
'Identify the specific range for sorting
Range("B6:T50").Select
'sort data by purchase date
'Header:=xlYes leaves the first row untouched
'Header:=xlGuess ??
Selection.Sort Key1:=Range("B6"), Order1:=xlAscending,
Header:=xlGuess

Thanks for your help,
Bernice



.

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
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
sort function for dates does not sort properly in Office 2007 Exc. Rosalie Excel Worksheet Functions 1 November 22nd 07 10:25 PM
data, sort option is grayed. how to sort on a column? Steve Richter Excel Discussion (Misc queries) 1 September 25th 07 03:25 PM
Ascending Sort formula, change to neg #: descending sort.. nastech Excel Discussion (Misc queries) 6 July 2nd 07 11:00 PM
Excel sort by Fill Color by custom list sort Dash4Cash Excel Discussion (Misc queries) 2 July 29th 05 10:45 PM


All times are GMT +1. The time now is 09:40 AM.

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"