Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Inserting Mulitple Criteria

Hello again,

I was given the following code and it works however I need make some minor
changes.

For Sub marine() I need to enter more than one criteria
Ex: Criteria = "Y09" and "Y08" and "777"

I need to run the code for alphanumeric as well as numeric. Thoughts?

Sub Marine()

' deletes all but criteria

Dim Criteria As String
Criteria = "Y08" 'Change to suit"
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
If InStr(1, C.Value, Criteria, 1) < 1 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Inserting Mulitple Criteria

nothing seems to happen when i run the code. I was able to use other code
though
to delete the data in a different way. Thanks for your help.

"joel" wrote:

Sub Marine()

' deletes all but criteria

Dim Criteria As String
Criteria = "Y08" 'Change to suit"
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
Select Case C
Case "Y09","Y08",777
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
End Select
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

"Peruanos72" wrote:

Hello again,

I was given the following code and it works however I need make some minor
changes.

For Sub marine() I need to enter more than one criteria
Ex: Criteria = "Y09" and "Y08" and "777"

I need to run the code for alphanumeric as well as numeric. Thoughts?

Sub Marine()

' deletes all but criteria

Dim Criteria As String
Criteria = "Y08" 'Change to suit"
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
If InStr(1, C.Value, Criteria, 1) < 1 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Inserting Mulitple Criteria

It seems to work with one piece of criteria but if there are 2 or more it
deletes everything.

"Jacob Skaria" wrote:

Please try and feedback

Sub Marine()

' deletes all but criteria

Dim arrCriteria As Variant
Dim intCriteria As Integer
Dim MyRange, MyRange1 As Range

arrCriteria = Array("Y08", "Y09", "Y07") 'Change to suit"
mycolumn = "E" 'Change to suit
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
For intCriteria = 0 To UBound(arrCriteria)
If InStr(1, C.Value, arrCriteria(intCriteria), 1) < 1 Then
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
End If
Next
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Peruanos72" wrote:

Hello again,

I was given the following code and it works however I need make some minor
changes.

For Sub marine() I need to enter more than one criteria
Ex: Criteria = "Y09" and "Y08" and "777"

I need to run the code for alphanumeric as well as numeric. Thoughts?

Sub Marine()

' deletes all but criteria

Dim Criteria As String
Criteria = "Y08" 'Change to suit"
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
If InStr(1, C.Value, Criteria, 1) < 1 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Inserting Mulitple Criteria

Try this

Sub Marine()

' deletes all but criteria

Dim arrCriteria As Variant
Dim intCriteria As Integer
Dim MyRange, MyRange1 As Range

arrCriteria = Array("Y08", "Y09", "Y07") 'Change to suit"
mycolumn = "E" 'Change to suit
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
For intCriteria = 0 To UBound(arrCriteria)
If InStr(1, C.Value, arrCriteria(intCriteria), 1) < 1 Then
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
Exit For
End If
Next
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Peruanos72" wrote:

It seems to work with one piece of criteria but if there are 2 or more it
deletes everything.

"Jacob Skaria" wrote:

Please try and feedback

Sub Marine()

' deletes all but criteria

Dim arrCriteria As Variant
Dim intCriteria As Integer
Dim MyRange, MyRange1 As Range

arrCriteria = Array("Y08", "Y09", "Y07") 'Change to suit"
mycolumn = "E" 'Change to suit
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
For intCriteria = 0 To UBound(arrCriteria)
If InStr(1, C.Value, arrCriteria(intCriteria), 1) < 1 Then
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
End If
Next
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Peruanos72" wrote:

Hello again,

I was given the following code and it works however I need make some minor
changes.

For Sub marine() I need to enter more than one criteria
Ex: Criteria = "Y09" and "Y08" and "777"

I need to run the code for alphanumeric as well as numeric. Thoughts?

Sub Marine()

' deletes all but criteria

Dim Criteria As String
Criteria = "Y08" 'Change to suit"
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
If InStr(1, C.Value, Criteria, 1) < 1 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Inserting Mulitple Criteria

It still deletes everything. Thanks very much for your help. I was able to
obtain code to do what I needed just in a different way. I now delete any row
where the cell in column "E" contains alpha characters.


Sub DeleteNonNumericRows()
LastRow = Range("E" & Rows.Count).End(xlUp).Row
For r = LastRow To 4 Step -1
If Not IsNumeric(Cells(r, "E")) Then
Rows(r).Delete
End If
Next
End Sub



"Jacob Skaria" wrote:

Try this

Sub Marine()

' deletes all but criteria

Dim arrCriteria As Variant
Dim intCriteria As Integer
Dim MyRange, MyRange1 As Range

arrCriteria = Array("Y08", "Y09", "Y07") 'Change to suit"
mycolumn = "E" 'Change to suit
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
For intCriteria = 0 To UBound(arrCriteria)
If InStr(1, C.Value, arrCriteria(intCriteria), 1) < 1 Then
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
Exit For
End If
Next
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Peruanos72" wrote:

It seems to work with one piece of criteria but if there are 2 or more it
deletes everything.

"Jacob Skaria" wrote:

Please try and feedback

Sub Marine()

' deletes all but criteria

Dim arrCriteria As Variant
Dim intCriteria As Integer
Dim MyRange, MyRange1 As Range

arrCriteria = Array("Y08", "Y09", "Y07") 'Change to suit"
mycolumn = "E" 'Change to suit
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
For intCriteria = 0 To UBound(arrCriteria)
If InStr(1, C.Value, arrCriteria(intCriteria), 1) < 1 Then
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
End If
Next
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Peruanos72" wrote:

Hello again,

I was given the following code and it works however I need make some minor
changes.

For Sub marine() I need to enter more than one criteria
Ex: Criteria = "Y09" and "Y08" and "777"

I need to run the code for alphanumeric as well as numeric. Thoughts?

Sub Marine()

' deletes all but criteria

Dim Criteria As String
Criteria = "Y08" 'Change to suit"
mycolumn = "E" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "4:" & mycolumn & LastRow)
For Each C In MyRange
If InStr(1, C.Value, Criteria, 1) < 1 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

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
Inserting Mulitple Criteria Jacob Skaria Excel Programming 0 April 15th 09 05:44 PM
Inserting Mulitple Criteria joel Excel Programming 0 April 15th 09 05:40 PM
COUNTIF Function with mulitple criteria? Corey Excel Worksheet Functions 6 January 28th 07 02:02 PM
LookUp with Mulitple Criteria TimR Excel Discussion (Misc queries) 4 July 13th 06 12:22 AM
mulitple criteria imjustme Excel Discussion (Misc queries) 9 September 2nd 05 02:07 AM


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