Determine if specific text is in a cell

J

Jen_T

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
 
A

Anthony

Not totally sure what you are trying to do...

try the worksheet change function and then test target.value for the text
you want

Regards

Anthony
 
L

Lars-Åke Aspelin

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
 
P

Per Jessen

Hi

This should do it:

Sub aaa()
Dim LastCell As Range
Dim cell As Range
Set LastCell = Range("P" & Rows.Count).End(xlUp)
For Each cell In Range("P2", LastCell).Cells
If cell.Value Like "*Grade A*" Then
cell.Offset(0, 10) = "Yes"
Else
cell.Offset(0, 10) = ""
End If
Next
End Sub

Regards,
Per
 
L

Libby

Try this

Dim InString
Dim SearchString
InString = "Grade A"
SearchString = Range("P2").Text
If InStr(1, SearchString, InString, vbTextCompare) > 0 Then
Range("Z2") = "Yes"
Else
Range("Z2") = ""
End If
 
J

Jen_T

Hi,
If I may ask an additional question, similar to the previous, how would I
write the code for the following:
Objective: I am looking to see if a cell value is equal to "0" if so,
remove, if not leave current text in that cell.

This is what I have for code so far:
Subttt()
Dim LastCell As Range
Dim cell As Range
Set LastCell = Range("F" & Rows.Count).End(xlUp)
For Each cell In Range("F2", LastCell).Cells
If cell.Value Like #0# Then
cell.Offset(0, 0) = ""
Else
cell.Offset(0, 0) = "F2"
End If
Next
End Sub
 
P

Per Jessen

Hi

Try this:

Sub ttt()
Dim LastCell As Range
Dim cell As Range
Set LastCell = Range("F" & Rows.Count).End(xlUp)
For Each cell In Range("F2", LastCell).Cells
If cell.Value = 0 Then
cell = ""
End If
Next
End Sub

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top