Thread
:
Conditionally retain rows
View Single Post
#
5
Posted to microsoft.public.excel.worksheet.functions
Don Guillett
external usenet poster
Posts: 10,124
Conditionally retain rows
Try this simpler idea and post back.
mystr = "59,3100,3101"
x = 3100'your value
If InStr(mystr, x) = 0 Then MsgBox "NO"
--
Don Guillett
SalesAid Software
"wal50" wrote in message
...
Thanks for the quick response. As I said, a bit repetitive, but here you
go:
'Delete Rows that do not match the list
Sub TrackingItemsWholesaleBeta()
Const strCriteria1 As String = "59"
Const strCriteria2 As String = "3100"
Const strCriteria3 As String = "3101"
Const strCriteria4 As String = "3102"
Const strCriteria5 As String = "3104"
Const strCriteria6 As String = "3117"
Const strCriteria7 As String = "3118"
Const strCriteria8 As String = "3121"
'Change to what is to be eliminated in above
Dim rngData As Range
Dim rngCell As Range
Dim rngDelete As Range
With Worksheets("Sheet1") '<<<<<Change to the Tab name
Set rngData = Intersect(.UsedRange, .Columns(2)) 'Change to the column
were the criteria is
End With
'One of the below sequences for each defined string
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria1) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria2) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria3) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria4) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria5) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria6) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria7) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
For Each rngCell In rngData
If LCase(rngCell.Value) = LCase(strCriteria8) Then
If rngDelete Is Nothing Then
Set rngDelete = rngCell
Else: Set rngDelete = Union(rngDelete, rngCell)
End If
End If
Next rngCell
If Not rngDelete Is Nothing Then _
rngDelete.EntireRow.Delete
End Sub
"Don Guillett" wrote:
As always, post your code for comments and suggestions.
--
Don Guillett
SalesAid Software
"wal50" wrote in message
...
I have a macro (thanks to this site) that deletes rows that do not meet
conditions. I now have reason retain rows that meet the conditions
(delete
rows where the conditons are not met). For example, I want to delete
all
rows where col2 < any of up to 12 different branch numbers.
I tried changing the = to < in the existing macro (which loops through
for
each condition) but it seems the logic deletes the row because it does
not
match condition 1, even if it would have matched a later condition.
The
row
is deleted by then.
Any ideas would be appreciated.
Thanks,
wal50
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett