View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Lars-Åke Aspelin[_2_] Lars-Åke Aspelin[_2_] is offline
external usenet poster
 
Posts: 913
Default Determine if specific text is in a cell

On Sat, 22 Aug 2009 13:06:01 -0700, Jen_T
wrote:

I have a worksheet that I would like to add a macro too.
I would like to look at cell, lets say "P2" and check to see if "Grade A"
is in the text. if true then enter the value "Yes" in cell Z2. I will then
copy/paste this lookup down in the z column. I know how to do the final piece
but not sure how to check a cell if certain text is within text of the cell.
This is what I have ,know this probably is incorrect.

With
Range=IF("P2"="*Grade A*" Then
Range Z2="Yes"
Else Not
Range Z2=""
End With



Try this macro:

Sub Jen_T()
With ActiveSheet
If InStr(Cells(2, "P"), "Grade A") Then
.Cells(2, "Z") = "Yes"
Else
.Cells(2, "Z") = ""
End If
End With
End Sub

Hope this helps / Lars-Åke