Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
toolman
 
Posts: n/a
Default finding last row in a fixed section then sort

I have a worksheet that has a fixed area cells a8:n40 this area will not be
filled and will contain blank rows. i am doing a sort in ascending order
first and then i want to select the rows that contain data and not blank rows
to do a second sort in descending order. Here is what i have already for the
second sort and it will error when placed in operation.

this first line works
worksheets("HD").Range("A8:n40").Sort Key1:=Worksheets("HD").Range("m8"),
Order1:=xlAscending 'xlAscending xlDescending

from this point it will not select the data and errors out

Dim LastRow As Integer 'This is the LAST Non Empty Row

LastRow = Worksheets("HD").UsedRange.Row - 1 + _
Worksheets("HD").UsedRange.Rows.Count

Worksheets("HD").Range("A8:0" & LastRow & ").Sort
Key1:=Worksheets("HD").Range("m8"), Order1:=xlDescending 'xlAscending
xlDescending

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default finding last row in a fixed section then sort

You don't mention what the error message is, but you appear to have a lone
double quote in this line:
Worksheets("HD").Range("A8:0" & LastRow & ").
You should not need the & " after Lastrow

--
Kevin Vaughn


"toolman" wrote:

I have a worksheet that has a fixed area cells a8:n40 this area will not be
filled and will contain blank rows. i am doing a sort in ascending order
first and then i want to select the rows that contain data and not blank rows
to do a second sort in descending order. Here is what i have already for the
second sort and it will error when placed in operation.

this first line works
worksheets("HD").Range("A8:n40").Sort Key1:=Worksheets("HD").Range("m8"),
Order1:=xlAscending 'xlAscending xlDescending

from this point it will not select the data and errors out

Dim LastRow As Integer 'This is the LAST Non Empty Row

LastRow = Worksheets("HD").UsedRange.Row - 1 + _
Worksheets("HD").UsedRange.Rows.Count

Worksheets("HD").Range("A8:0" & LastRow & ").Sort
Key1:=Worksheets("HD").Range("m8"), Order1:=xlDescending 'xlAscending
xlDescending

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
toolman
 
Posts: n/a
Default finding last row in a fixed section then sort

the error message is

1004 Application-defined or object-defined error

i made the corrections and the error is still there.

"Kevin Vaughn" wrote:

You don't mention what the error message is, but you appear to have a lone
double quote in this line:
Worksheets("HD").Range("A8:0" & LastRow & ").
You should not need the & " after Lastrow

--
Kevin Vaughn


"toolman" wrote:

I have a worksheet that has a fixed area cells a8:n40 this area will not be
filled and will contain blank rows. i am doing a sort in ascending order
first and then i want to select the rows that contain data and not blank rows
to do a second sort in descending order. Here is what i have already for the
second sort and it will error when placed in operation.

this first line works
worksheets("HD").Range("A8:n40").Sort Key1:=Worksheets("HD").Range("m8"),
Order1:=xlAscending 'xlAscending xlDescending

from this point it will not select the data and errors out

Dim LastRow As Integer 'This is the LAST Non Empty Row

LastRow = Worksheets("HD").UsedRange.Row - 1 + _
Worksheets("HD").UsedRange.Rows.Count

Worksheets("HD").Range("A8:0" & LastRow & ").Sort
Key1:=Worksheets("HD").Range("m8"), Order1:=xlDescending 'xlAscending
xlDescending

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default finding last row in a fixed section then sort

I just pasted what I originally took as an O to my spreadsheet and compared
it with a 0. I would say that is your problem
Worksheets("HD").Range("A8:0" & LastRow & ").Sort
the a8:0 should be a8:O (or some other column letter)


--
Kevin Vaughn


"toolman" wrote:

I have a worksheet that has a fixed area cells a8:n40 this area will not be
filled and will contain blank rows. i am doing a sort in ascending order
first and then i want to select the rows that contain data and not blank rows
to do a second sort in descending order. Here is what i have already for the
second sort and it will error when placed in operation.

this first line works
worksheets("HD").Range("A8:n40").Sort Key1:=Worksheets("HD").Range("m8"),
Order1:=xlAscending 'xlAscending xlDescending

from this point it will not select the data and errors out

Dim LastRow As Integer 'This is the LAST Non Empty Row

LastRow = Worksheets("HD").UsedRange.Row - 1 + _
Worksheets("HD").UsedRange.Rows.Count

Worksheets("HD").Range("A8:0" & LastRow & ").Sort
Key1:=Worksheets("HD").Range("m8"), Order1:=xlDescending 'xlAscending
xlDescending

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
toolman
 
Posts: n/a
Default finding last row in a fixed section then sort

Kevin

Thanks for the extra set of eyes
The sort works now but it still includes the rows that do not have data.

"Kevin Vaughn" wrote:

I just pasted what I originally took as an O to my spreadsheet and compared
it with a 0. I would say that is your problem
Worksheets("HD").Range("A8:0" & LastRow & ").Sort
the a8:0 should be a8:O (or some other column letter)


--
Kevin Vaughn


"toolman" wrote:

I have a worksheet that has a fixed area cells a8:n40 this area will not be
filled and will contain blank rows. i am doing a sort in ascending order
first and then i want to select the rows that contain data and not blank rows
to do a second sort in descending order. Here is what i have already for the
second sort and it will error when placed in operation.

this first line works
worksheets("HD").Range("A8:n40").Sort Key1:=Worksheets("HD").Range("m8"),
Order1:=xlAscending 'xlAscending xlDescending

from this point it will not select the data and errors out

Dim LastRow As Integer 'This is the LAST Non Empty Row

LastRow = Worksheets("HD").UsedRange.Row - 1 + _
Worksheets("HD").UsedRange.Rows.Count

Worksheets("HD").Range("A8:0" & LastRow & ").Sort
Key1:=Worksheets("HD").Range("m8"), Order1:=xlDescending 'xlAscending
xlDescending



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default finding last row in a fixed section then sort

I don't know if this is your problem, but I do notice that you are using
usedrange. There are times when usedrange is not correct. From Excel, try
doing cntl-end and see if it takes you past rows/columns that have data. If
so, try highlighting, for instance the extra rows, and right-click and choose
delete entire-rows. Then save, and see if a cntl-end now takes you to the
true end of your data.
--
Kevin Vaughn


"toolman" wrote:

Kevin

Thanks for the extra set of eyes
The sort works now but it still includes the rows that do not have data.

"Kevin Vaughn" wrote:

I just pasted what I originally took as an O to my spreadsheet and compared
it with a 0. I would say that is your problem
Worksheets("HD").Range("A8:0" & LastRow & ").Sort
the a8:0 should be a8:O (or some other column letter)


--
Kevin Vaughn


"toolman" wrote:

I have a worksheet that has a fixed area cells a8:n40 this area will not be
filled and will contain blank rows. i am doing a sort in ascending order
first and then i want to select the rows that contain data and not blank rows
to do a second sort in descending order. Here is what i have already for the
second sort and it will error when placed in operation.

this first line works
worksheets("HD").Range("A8:n40").Sort Key1:=Worksheets("HD").Range("m8"),
Order1:=xlAscending 'xlAscending xlDescending

from this point it will not select the data and errors out

Dim LastRow As Integer 'This is the LAST Non Empty Row

LastRow = Worksheets("HD").UsedRange.Row - 1 + _
Worksheets("HD").UsedRange.Rows.Count

Worksheets("HD").Range("A8:0" & LastRow & ").Sort
Key1:=Worksheets("HD").Range("m8"), Order1:=xlDescending 'xlAscending
xlDescending

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
Select rows and sort based on type Sarah Excel Discussion (Misc queries) 0 October 11th 05 05:06 PM
sorting more than 3 keys Brooke Excel Discussion (Misc queries) 3 June 18th 05 04:52 AM
sort by section number alslm Excel Discussion (Misc queries) 1 April 14th 05 04:55 PM
"-" ignored in sort Mike H Excel Discussion (Misc queries) 8 January 2nd 05 07:48 AM
HELP! How do you--> Lock a set of rows but also link worksheets to FRUSTRATED Excel Discussion (Misc queries) 6 December 29th 04 10:05 PM


All times are GMT +1. The time now is 11:31 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"