PC Review


Reply
Thread Tools Rate Thread

How to delete individual rows according to criteria?

 
 
=?Utf-8?B?am9obmFiZGw=?=
Guest
Posts: n/a
 
      7th Sep 2007
I want to delete specific rows if one field in the row contains a particular
alphnumeric string.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      7th Sep 2007
Sub Delete()
Dim myRange As Range
Dim lRow As Long
Dim lCol As Long
Dim aWS As Worksheet

Set aWS = ActiveSheet
lRow = aWS.Cells(aWS.Rows.Count, "A").End(xlUp).Row
Set myRange = Nothing
For i = 1 To lRow
lCol = aWS.Cells(lRow, aWS.Columns.Count).End(xlToLeft).Column
For j = 1 To lCol
If aWS.Cells(i, j).Value = "Your value" Then
If myRange Is Nothing Then
Set myRange = aWS.Cells(i, j)
Else
Set myRange = Union(myRange, aWS.Cells(i, j))
End If
Exit For
Next j
Next i

If Not myRange Is Nothing Then
myRange.EntireRow.Delete
End If

End Sub


Modify as needed.
--
HTH,
Barb Reinhardt



"johnabdl" wrote:

> I want to delete specific rows if one field in the row contains a particular
> alphnumeric string.

 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      7th Sep 2007
Oops, I forgot an end if

Sub Delete()
Dim myRange As Range
Dim lRow As Long
Dim lCol As Long
Dim aWS As Worksheet

Set aWS = ActiveSheet
lRow = aWS.Cells(aWS.Rows.Count, "A").End(xlUp).Row
Set myRange = Nothing
For i = 1 To lRow
lCol = aWS.Cells(i, aWS.Columns.Count).End(xlToLeft).Column
For j = 1 To lCol
If lcase(aWS.Cells(i, j).text = "your value" Then
If myRange Is Nothing Then
Set myRange = aWS.Cells(i, j)
Else
Set myRange = Union(myRange, aWS.Cells(i, j))
End If
Exit For
End If
Next j
Next i

If Not myRange Is Nothing Then
myRange.EntireRow.Delete
End If

End Sub

--
HTH,
Barb Reinhardt



"johnabdl" wrote:

> I want to delete specific rows if one field in the row contains a particular
> alphnumeric string.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Rows on Set Criteria Sue Microsoft Excel Programming 14 20th Oct 2008 01:47 PM
Delete Rows that fit a certain criteria =?Utf-8?B?anBpdHRhcmk=?= Microsoft Excel Programming 3 2nd Nov 2007 03:22 PM
Delete rows with different criteria =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 7 13th Jul 2005 05:38 PM
delete rows with criteria S.E. Microsoft Excel Programming 5 9th Sep 2004 04:04 PM
Delete rows w/o criteria RickK Microsoft Excel Programming 2 31st Oct 2003 04:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:39 PM.