Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Generalising Deleting Rows after AUTOFILTER

I have this code:

Sub Macro2()

Range("A1").AutoFilter Field:=1, Criteria1:="b"
Rows("7:9").Delete Shift:=xlUp
Selection.AutoFilter

End Sub

and its used on a small table like this:

Name Age
a 5
c 75
c 96
c 4
c 8
b 59
b 8
b 7

I've got no way of predicting how many rows there'll be in the table,
so how do I generalise the second row of the code? i.e the bit
'Rows("7:9")'.
Or do I need to look into an alternative approach?

Any help greatly appreciated,
Jason.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Generalising Deleting Rows after AUTOFILTER

Sub Macro2()
Dim rng As Range
Range("A1").AutoFilter Field:=1, Criteria1:="b"
Set rng = ActiveSheet.AutoFilter.Range
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
rng.EntireRow.Delete
Range("A1").AutoFilter
End Sub


Will delete all the entries with b

Test on a copy of your data.

--
Regards,
Tom Ogilvy


"jason" wrote in message
om...
I have this code:

Sub Macro2()

Range("A1").AutoFilter Field:=1, Criteria1:="b"
Rows("7:9").Delete Shift:=xlUp
Selection.AutoFilter

End Sub

and its used on a small table like this:

Name Age
a 5
c 75
c 96
c 4
c 8
b 59
b 8
b 7

I've got no way of predicting how many rows there'll be in the table,
so how do I generalise the second row of the code? i.e the bit
'Rows("7:9")'.
Or do I need to look into an alternative approach?

Any help greatly appreciated,
Jason.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Generalising Deleting Rows after AUTOFILTER

Cheers Tom
I think this little beauty'll be getting used a lot
Jason


"Tom Ogilvy" wrote in message ...
Sub Macro2()
Dim rng As Range
Range("A1").AutoFilter Field:=1, Criteria1:="b"
Set rng = ActiveSheet.AutoFilter.Range
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
rng.EntireRow.Delete
Range("A1").AutoFilter
End Sub


Will delete all the entries with b

Test on a copy of your data.

--
Regards,
Tom Ogilvy


"jason" wrote in message
om...
I have this code:

Sub Macro2()

Range("A1").AutoFilter Field:=1, Criteria1:="b"
Rows("7:9").Delete Shift:=xlUp
Selection.AutoFilter

End Sub

and its used on a small table like this:

Name Age
a 5
c 75
c 96
c 4
c 8
b 59
b 8
b 7

I've got no way of predicting how many rows there'll be in the table,
so how do I generalise the second row of the code? i.e the bit
'Rows("7:9")'.
Or do I need to look into an alternative approach?

Any help greatly appreciated,
Jason.

  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Generalising Deleting Rows after AUTOFILTER

hi.
there is no way to generalize code. code is specific in
what it does.
you will have to add code that will find and select what
you wish to delete.
this line will open the find dialog box
Application.Dialogs(xlDialogFormulaFind).Show

-----Original Message-----
I have this code:

Sub Macro2()

Range("A1").AutoFilter Field:=1, Criteria1:="b"
Rows("7:9").Delete Shift:=xlUp
Selection.AutoFilter

End Sub

and its used on a small table like this:

Name Age
a 5
c 75
c 96
c 4
c 8
b 59
b 8
b 7

I've got no way of predicting how many rows there'll be

in the table,
so how do I generalise the second row of the code? i.e

the bit
'Rows("7:9")'.
Or do I need to look into an alternative approach?

Any help greatly appreciated,
Jason.
.

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
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Links and Linking in Excel 1 November 13th 08 08:44 AM
Excel 2007 Autofilter deleting unfiltered Data Chris Excel Worksheet Functions 0 May 15th 08 11:06 PM
Deleting rows in a range using Autofilter Connie Excel Discussion (Misc queries) 3 October 17th 06 01:47 PM
Deleting results of an AutoFilter excluding top row Shirley Munro Excel Discussion (Misc queries) 1 February 2nd 06 02:11 PM
deleting duplicated cells in a list via advanced autofilter? petevang Excel Discussion (Misc queries) 1 December 7th 05 03:54 PM


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