Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete non-selected rows

Maybe I'm just being thick-headed here. Seems this should be so easy. Excel
2002. I want to delete all the rows that are not selected by the user. I
tried this code to no avail:

ShtBtm=cells(65536,"a").end(xlup).row
for a=shtbtm to 2 step-1
if not rows(a).selected then rows(a).delete
next a

That's what I want. Excel doesn't like rows(a).selected. Help!
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete non-selected rows

Sub Tester1()
shtbtm = Cells(65536, "a").End(xlUp).Row
For a = shtbtm To 2 Step -1
If Intersect(Rows(a), Selection) Is Nothing Then
Rows(a).Delete
End If
Next a

End Sub

--
Regards,
Tom Ogilvy


"SparePersn" wrote in message
...
Maybe I'm just being thick-headed here. Seems this should be so easy.

Excel
2002. I want to delete all the rows that are not selected by the user. I
tried this code to no avail:

ShtBtm=cells(65536,"a").end(xlup).row
for a=shtbtm to 2 step-1
if not rows(a).selected then rows(a).delete
next a

That's what I want. Excel doesn't like rows(a).selected. Help!
Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Delete non-selected rows

I have not got the code- just a suggestion.

1. selection.address returns a comma separated list of all the rows selected.
2. you should know the used range in the worksheet
3. write a loop for eah row of the used range
if there is no INTERSECT of each element of 1 within the loop row,
record the loop row in a variable
4. at the end of the loop, delete the rows recorded.

You can't delete within the loop.


"SparePersn" wrote:

Maybe I'm just being thick-headed here. Seems this should be so easy. Excel
2002. I want to delete all the rows that are not selected by the user. I
tried this code to no avail:

ShtBtm=cells(65536,"a").end(xlup).row
for a=shtbtm to 2 step-1
if not rows(a).selected then rows(a).delete
next a

That's what I want. Excel doesn't like rows(a).selected. Help!
Thanks!

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
delete columns and rows-cells equalling zero or any selected value Scottie Excel Worksheet Functions 2 May 9th 05 08:47 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM
Delete Selected Rows Ken[_18_] Excel Programming 2 February 5th 04 10:33 PM
Need a macro to delete selected rows RKettle Excel Programming 5 January 13th 04 05:29 PM
Delete/Collapse Rows Not Selected Cindy Excel Programming 19 November 21st 03 03:38 AM


All times are GMT +1. The time now is 02:25 AM.

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"