Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default delete rows with criteria

I want to delete all rows that do not have the word "gift" in column A. The
cells in column A often have "gift" along with some other words. It must be
simple to write a wildcard that includes "gift", but I don't know how yet.
Thanks for your help.

Scott


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete rows with criteria

Try this

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "A").Value Like "*gift*" Then .Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

You can also Filter (faster)
Look here
http://www.rondebruin.nl/delete.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"S.E." wrote in message ...
I want to delete all rows that do not have the word "gift" in column A. The cells in column A often have "gift" along with some
other words. It must be simple to write a wildcard that includes "gift", but I don't know how yet. Thanks for your help.

Scott




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default delete rows with criteria

That's just about what I need. The only problem is that I want to delete the
row if it does NOT contain "gift". This macro deletes the ones that DO
contain "gift".

Scott

"Ron de Bruin" wrote in message
...
Try this

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "A").Value Like "*gift*" Then
.Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

You can also Filter (faster)
Look here
http://www.rondebruin.nl/delete.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"S.E." wrote in message
...
I want to delete all rows that do not have the word "gift" in column A.
The cells in column A often have "gift" along with some other words. It
must be simple to write a wildcard that includes "gift", but I don't know
how yet. Thanks for your help.

Scott






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete rows with criteria

Oops

ElseIf Not .Cells(Lrow, "A").Value Like "*gift*" Then .Rows(Lrow).Delete


--
Regards Ron de Bruin
http://www.rondebruin.nl


"S.E." wrote in message ...
That's just about what I need. The only problem is that I want to delete the row if it does NOT contain "gift". This macro deletes
the ones that DO contain "gift".

Scott

"Ron de Bruin" wrote in message ...
Try this

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "A").Value Like "*gift*" Then .Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

You can also Filter (faster)
Look here
http://www.rondebruin.nl/delete.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"S.E." wrote in message ...
I want to delete all rows that do not have the word "gift" in column A. The cells in column A often have "gift" along with some
other words. It must be simple to write a wildcard that includes "gift", but I don't know how yet. Thanks for your help.

Scott








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default delete rows with criteria

Another thing. This seems to just clear the rows. In the macro I would like
to move the other rows up to take the place of the deleted rows.

Scott

"Ron de Bruin" wrote in message
...
Try this

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "A").Value Like "*gift*" Then
.Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

You can also Filter (faster)
Look here
http://www.rondebruin.nl/delete.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"S.E." wrote in message
...
I want to delete all rows that do not have the word "gift" in column A.
The cells in column A often have "gift" along with some other words. It
must be simple to write a wildcard that includes "gift", but I don't know
how yet. Thanks for your help.

Scott








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default delete rows with criteria

Nevermind. Now it works. Thanks Ron.

Scott

"S.E." wrote in message
...
Another thing. This seems to just clear the rows. In the macro I would
like to move the other rows up to take the place of the deleted rows.

Scott

"Ron de Bruin" wrote in message
...
Try this

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "A").Value Like "*gift*" Then
.Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

You can also Filter (faster)
Look here
http://www.rondebruin.nl/delete.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"S.E." wrote in message
...
I want to delete all rows that do not have the word "gift" in column A.
The cells in column A often have "gift" along with some other words. It
must be simple to write a wildcard that includes "gift", but I don't know
how yet. Thanks for your help.

Scott








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 all rows if criteria not matched ongcong Excel Discussion (Misc queries) 4 August 25th 08 07:58 PM
Delete rows if specific criteria not met. SITCFanTN Excel Worksheet Functions 3 July 5th 06 12:20 AM
Delete rows based on criteria Chris_t_2k5 Excel Discussion (Misc queries) 2 April 11th 06 01:52 PM
Delete rows based on certain criteria Coal Miner Excel Discussion (Misc queries) 2 March 3rd 06 05:56 PM
Delete rows w/o criteria RickK[_2_] Excel Programming 2 October 31st 03 04:48 PM


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