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

I want to delete specific rows if one field in the row contains a particular
alphnumeric string.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How to delete individual rows according to criteria?

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How to delete individual rows according to criteria?

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
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
VB Delete rows that do not match criteria rlee1999 Excel Programming 2 November 1st 06 11:19 PM
Delete rows based on criteria Chris_t_2k5 Excel Discussion (Misc queries) 2 April 11th 06 01:52 PM
Delete rows with different criteria John Excel Programming 7 July 13th 05 05:38 PM
delete rows with criteria S.E. Excel Programming 5 September 9th 04 04:04 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 05:22 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"