Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Danny
 
Posts: n/a
Default VBA, Excel - Find Range, Sort

Please correct my macro:

Application.Goto Reference:="AAA"
ActiveCell.Resize(xlDown, 9).Select

I'm trying to write a macro to find a named range, then highlight the rows
(?) down to the last cell and to the right (col) 9 columns so I can sort it
ascending (header is AAA).

I can copy the macro for the sorting by doing it step by step but I don't
know how select the range.

Thanks you.


  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Danny,

xlDown is an Excel constant, and is a negative number, -4121 to be exact.
Passing a negative number is invalid as you cannot have a negative numnber
of rows.

I think you are looking for something like

With Activecell
iLastRow = cells(rows.Count,.Column).end(xlup).Row
Set rng = .Resize(ilastrow - .Row + 1, 9)
End With
rng.Sort etc.

--
HTH

Bob Phillips

"Danny" wrote in message
...
Please correct my macro:

Application.Goto Reference:="AAA"
ActiveCell.Resize(xlDown, 9).Select

I'm trying to write a macro to find a named range, then highlight the rows
(?) down to the last cell and to the right (col) 9 columns so I can sort

it
ascending (header is AAA).

I can copy the macro for the sorting by doing it step by step but I don't
know how select the range.

Thanks you.




  #3   Report Post  
Danny
 
Posts: n/a
Default

Hi Bob, thanks for your prompt response. I copied your formula and for some
reason did not work. Please write me another macro just so I can go to the
named range and highlight the rows(???) and the 9 columns from the named
range.

Thanks again.

"Bob Phillips" wrote:

Danny,

xlDown is an Excel constant, and is a negative number, -4121 to be exact.
Passing a negative number is invalid as you cannot have a negative numnber
of rows.

I think you are looking for something like

With Activecell
iLastRow = cells(rows.Count,.Column).end(xlup).Row
Set rng = .Resize(ilastrow - .Row + 1, 9)
End With
rng.Sort etc.

--
HTH

Bob Phillips

"Danny" wrote in message
...
Please correct my macro:

Application.Goto Reference:="AAA"
ActiveCell.Resize(xlDown, 9).Select

I'm trying to write a macro to find a named range, then highlight the rows
(?) down to the last cell and to the right (col) 9 columns so I can sort

it
ascending (header is AAA).

I can copy the macro for the sorting by doing it step by step but I don't
know how select the range.

Thanks you.





  #4   Report Post  
Danny
 
Posts: n/a
Default

Hi Bob,

Sorry, sorry, your formula worked perfectly! I think when I copied and
pasted it something else was copied pasted with it. I "cleaned" the macro and
it work perfectly.

Thanks a million!

"Danny" wrote:

Hi Bob, thanks for your prompt response. I copied your formula and for some
reason did not work. Please write me another macro just so I can go to the
named range and highlight the rows(???) and the 9 columns from the named
range.

Thanks again.

"Bob Phillips" wrote:

Danny,

xlDown is an Excel constant, and is a negative number, -4121 to be exact.
Passing a negative number is invalid as you cannot have a negative numnber
of rows.

I think you are looking for something like

With Activecell
iLastRow = cells(rows.Count,.Column).end(xlup).Row
Set rng = .Resize(ilastrow - .Row + 1, 9)
End With
rng.Sort etc.

--
HTH

Bob Phillips

"Danny" wrote in message
...
Please correct my macro:

Application.Goto Reference:="AAA"
ActiveCell.Resize(xlDown, 9).Select

I'm trying to write a macro to find a named range, then highlight the rows
(?) down to the last cell and to the right (col) 9 columns so I can sort

it
ascending (header is AAA).

I can copy the macro for the sorting by doing it step by step but I don't
know how select the range.

Thanks you.





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
Sort range changes during sort coffedrinker2003 Excel Discussion (Misc queries) 1 May 24th 05 11:53 PM
Sort Ascending button - Excel 2003 bigwheel Excel Discussion (Misc queries) 1 May 23rd 05 11:10 PM
find a cells from a range of cell kelvintaycc Excel Worksheet Functions 2 April 2nd 05 07:20 PM
How do I sort for the maximum values in each year in excel? The Wrightster Excel Discussion (Misc queries) 3 February 24th 05 05:43 PM
How do I reference and sort a range of numbers in Excel 97? Old Northern Excel Worksheet Functions 3 December 14th 04 03:15 PM


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