Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default deleting rows in a worksheet if condition is met

hi,

I am trying to come up with a code that will somehow delete an entire row if
it's content in a particular column meets the condition. Say I want to
delete the rows whose Status column says approved.

Anybody can help?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default deleting rows in a worksheet if condition is met

You can do it manually by applying Autofilter to the status column and
selecting "approved" from the drop-down. Then highlight all the
visible rows and click on Edit | Delete Row. Then select "All" from
the filter drop-down.

Hope this helps.

Pete

On Oct 24, 5:23*pm, destine wrote:
hi,

I am trying to come up with a code that will somehow delete an entire row if
it's content in a particular column meets the condition. *Say I want to
delete the rows whose Status column says approved.

Anybody can help?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default deleting rows in a worksheet if condition is met

Hi,

Right click your sheet tab, view code and paste this in. Change the letter
in the line
mycolumn = "C" 'Change to suit
to the column where your string is.

Sub copyit()
mycolumn = "C" 'Change to suit
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "1:" & mycolumn & lastrow)
For Each c In MyRange
If UCase(c.Value) = "APPROVED" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub


Mike

"destine" wrote:

hi,

I am trying to come up with a code that will somehow delete an entire row if
it's content in a particular column meets the condition. Say I want to
delete the rows whose Status column says approved.

Anybody can help?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default deleting rows in a worksheet if condition is met

I like this code and it works for some of my applications as well. I need
something similar that will delete the row if the column contains "FM" in a
text string (not equal to). I also need syntax that would delete the row if
it does NOT contain "FM".

Can that be done with your code here?

"Mike H" wrote:

Hi,

Right click your sheet tab, view code and paste this in. Change the letter
in the line
mycolumn = "C" 'Change to suit
to the column where your string is.

Sub copyit()
mycolumn = "C" 'Change to suit
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "1:" & mycolumn & lastrow)
For Each c In MyRange
If UCase(c.Value) = "APPROVED" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub


Mike

"destine" wrote:

hi,

I am trying to come up with a code that will somehow delete an entire row if
it's content in a particular column meets the condition. Say I want to
delete the rows whose Status column says approved.

Anybody can help?

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
deleting condition after the first duplicate daphoenix Excel Worksheet Functions 9 June 25th 08 06:38 PM
Deleting rows from a worksheet automatically mg_sv_r Excel Worksheet Functions 2 May 19th 06 03:45 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
deleting hidden rows so i can print only the rows showing?????? jenn Excel Worksheet Functions 0 October 6th 05 04:05 PM
How do I resize a worksheet after deleting rows? Jay Jay Excel Discussion (Misc queries) 2 July 25th 05 09:31 PM


All times are GMT +1. The time now is 05:08 PM.

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"