MACRO

xxsalahxx

Active Member
Joined
Jun 25, 2011
Messages
316
Office Version
  1. 2007
Hello im using the macro below and it is working well, however, i need to add to this to extract not only the word RED but also BLUE is there anyway to add to this macro to do this?
Thank you in advance.

Sub Foo()
Dim Cl As Range
Dim i As Long
Dim aTokens As String

i = 5
aTokens = ("RED")
With Sheets("DATA")
For Each Cl In .Range("C5", .Range("C" & Rows.Count).End(xlUp))
If InStr(1, Cl.Value, aTokens, vbTextCompare) Then
Cl.EntireRow.Copy Sheets("data red and blue").Rows(i)
i = i + 1
End If
Next Cl
End With
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this:
VBA Code:
Sub Foo()
Dim Cl As Range, i As Long, aTokens As String, bTokens As String

i = 5
aTokens = ("RED")
bTokens = ("BLUE")
With Sheets("DATA")
For Each Cl In .Range("C5", .Range("C" & Rows.Count).End(xlUp))
If InStr(1, Cl.Value, aTokens, vbTextCompare) Or InStr(1, Cl.Value, bTokens, vbTextCompare) Then
Cl.EntireRow.Copy Sheets("data red and blue").Rows(i)
i = i + 1
End If
Next Cl
End With
End Sub
 
Upvote 0
Solution
Im afraid thats not working any other ideas?
Thank you for replying so quickly
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top