Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
djhs63
 
Posts: n/a
Default how do I delete all rows that match a condition?

I want to record a macro to delete all rows in a worksheet where a specified
column entry matches a condition (e.g. "where column D=DONCASTER or LEEDS or
HALIFAX")
  #2   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

djhs,

The typical code to do that is:

On Error Resume Next
Columns("D:D").AutoFilter Field:=1, Criteria1:="DONCASTER"
Range("D2:D65536").SpecialCells(xlCellTypeVisible) .EntireRow.Delete

Repeat the two lines above for each condition, then use the line

Columns("D:D").AutoFilter Field:=1

to turn off the filter, and your macro is done.

HTH,
Bernie
MS Excel MVP

"djhs63" wrote in message
...
I want to record a macro to delete all rows in a worksheet where a

specified
column entry matches a condition (e.g. "where column D=DONCASTER or LEEDS

or
HALIFAX")



  #3   Report Post  
djhs63
 
Posts: n/a
Default

Bernie,

thanks very much - is there any way to concatenate conditions in one
statement, like Criteria1:="DONCASTER or HALIFAX or LEEDS"?

Regards,
djhs

"Bernie Deitrick" wrote:

djhs,

The typical code to do that is:

On Error Resume Next
Columns("D:D").AutoFilter Field:=1, Criteria1:="DONCASTER"
Range("D2:D65536").SpecialCells(xlCellTypeVisible) .EntireRow.Delete

Repeat the two lines above for each condition, then use the line

Columns("D:D").AutoFilter Field:=1

to turn off the filter, and your macro is done.

HTH,
Bernie
MS Excel MVP

"djhs63" wrote in message
...
I want to record a macro to delete all rows in a worksheet where a

specified
column entry matches a condition (e.g. "where column D=DONCASTER or LEEDS

or
HALIFAX")




  #4   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

djhs,

You can do only two at a time (using OR - record a macro for the syntax), so
it's easier to just copy and paste, or loop through using a variable as the
parameter.

HTH,
Bernie
MS Excel MVP


"djhs63" wrote in message
...
Bernie,

thanks very much - is there any way to concatenate conditions in one
statement, like Criteria1:="DONCASTER or HALIFAX or LEEDS"?

Regards,
djhs

"Bernie Deitrick" wrote:

djhs,

The typical code to do that is:

On Error Resume Next
Columns("D:D").AutoFilter Field:=1, Criteria1:="DONCASTER"
Range("D2:D65536").SpecialCells(xlCellTypeVisible) .EntireRow.Delete

Repeat the two lines above for each condition, then use the line

Columns("D:D").AutoFilter Field:=1

to turn off the filter, and your macro is done.

HTH,
Bernie
MS Excel MVP

"djhs63" wrote in message
...
I want to record a macro to delete all rows in a worksheet where a

specified
column entry matches a condition (e.g. "where column D=DONCASTER or
LEEDS

or
HALIFAX")






  #5   Report Post  
KL
 
Posts: n/a
Default

Hi,

Another way of doing the same:

Sub Test()
With ActiveSheet
For i = .Cells(.Rows.Count, "D").End(xlUp).Row To 2 Step -1
Select Case .Cells(i, "D").Value
Case "DONCASTER", "HALIFAX", "LEEDS"
If rng < "" Then rng = rng & ","
rng = rng & .Cells(i, "D").Address
End Select
Next i
.Range(rng).EntireRow.Delete
End With
End Sub

Regards,
KL

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
djhs,

You can do only two at a time (using OR - record a macro for the syntax),
so it's easier to just copy and paste, or loop through using a variable as
the parameter.

HTH,
Bernie
MS Excel MVP


"djhs63" wrote in message
...
Bernie,

thanks very much - is there any way to concatenate conditions in one
statement, like Criteria1:="DONCASTER or HALIFAX or LEEDS"?

Regards,
djhs

"Bernie Deitrick" wrote:

djhs,

The typical code to do that is:

On Error Resume Next
Columns("D:D").AutoFilter Field:=1, Criteria1:="DONCASTER"
Range("D2:D65536").SpecialCells(xlCellTypeVisible) .EntireRow.Delete

Repeat the two lines above for each condition, then use the line

Columns("D:D").AutoFilter Field:=1

to turn off the filter, and your macro is done.

HTH,
Bernie
MS Excel MVP

"djhs63" wrote in message
...
I want to record a macro to delete all rows in a worksheet where a
specified
column entry matches a condition (e.g. "where column D=DONCASTER or
LEEDS
or
HALIFAX")









  #6   Report Post  
djhs63
 
Posts: n/a
Default

KT thanks - please could you suggest syntax for the condition where contents
of column D are "not equal to DONCASTER, LEEDS, HALIFAX"

"Bernie Deitrick" wrote:

djhs,

You can do only two at a time (using OR - record a macro for the syntax), so
it's easier to just copy and paste, or loop through using a variable as the
parameter.

HTH,
Bernie
MS Excel MVP


"djhs63" wrote in message
...
Bernie,

thanks very much - is there any way to concatenate conditions in one
statement, like Criteria1:="DONCASTER or HALIFAX or LEEDS"?

Regards,
djhs

"Bernie Deitrick" wrote:

djhs,

The typical code to do that is:

On Error Resume Next
Columns("D:D").AutoFilter Field:=1, Criteria1:="DONCASTER"
Range("D2:D65536").SpecialCells(xlCellTypeVisible) .EntireRow.Delete

Repeat the two lines above for each condition, then use the line

Columns("D:D").AutoFilter Field:=1

to turn off the filter, and your macro is done.

HTH,
Bernie
MS Excel MVP

"djhs63" wrote in message
...
I want to record a macro to delete all rows in a worksheet where a
specified
column entry matches a condition (e.g. "where column D=DONCASTER or
LEEDS
or
HALIFAX")






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 repeating rows aledger Excel Worksheet Functions 2 March 4th 05 08:43 PM
delete empty rows between rows with text Paulo Baptista Excel Discussion (Misc queries) 2 February 28th 05 03:41 PM
How to delete duplicate rows in Excel 2000? PAL@Emory Excel Discussion (Misc queries) 1 January 28th 05 03:08 PM
How do I delete blank rows at the bottom of a spreadsheet to get . Miklaurie Excel Discussion (Misc queries) 1 January 26th 05 02:30 PM
Listing Multiple Rows from Match Sean Larkin Excel Worksheet Functions 7 December 21st 04 01:29 AM


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