PC Review


Reply
Thread Tools Rate Thread

Determine if specific text is in a cell

 
 
Jen_T
Guest
Posts: n/a
 
      22nd Aug 2009
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

 
Reply With Quote
 
 
 
 
Anthony
Guest
Posts: n/a
 
      22nd Aug 2009
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

"Jen_T" <(E-Mail Removed)> wrote in message
news:6C621586-9AE3-4D35-B501-(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Lars-Åke Aspelin
Guest
Posts: n/a
 
      22nd Aug 2009
On Sat, 22 Aug 2009 13:06:01 -0700, Jen_T
<(E-Mail Removed)> 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
 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      22nd Aug 2009
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

"Jen_T" <(E-Mail Removed)> skrev i meddelelsen
news:6C621586-9AE3-4D35-B501-(E-Mail Removed)...
>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
>


 
Reply With Quote
 
Libby
Guest
Posts: n/a
 
      22nd Aug 2009
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

"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
>

 
Reply With Quote
 
Jen_T
Guest
Posts: n/a
 
      25th Aug 2009
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

"Per Jessen" wrote:

> 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
>
> "Jen_T" <(E-Mail Removed)> skrev i meddelelsen
> news:6C621586-9AE3-4D35-B501-(E-Mail Removed)...
> >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
> >

>
>

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      25th Aug 2009
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

"Jen_T" <(E-Mail Removed)> skrev i meddelelsen
news:5E73826A-E2DA-4D54-92BB-(E-Mail Removed)...
> 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
>
> "Per Jessen" wrote:
>
>> 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
>>
>> "Jen_T" <(E-Mail Removed)> skrev i meddelelsen
>> news:6C621586-9AE3-4D35-B501-(E-Mail Removed)...
>> >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
>> >

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine the value within specific cell position? Eric Microsoft Excel Misc 5 9th Apr 2010 01:15 PM
Determine the colour of text in each cell in a range of cells Khurram Microsoft Excel Programming 7 5th Feb 2007 02:46 PM
How to determine whether text in cell needs to be wrapped? Joe HM Microsoft Excel Programming 3 25th May 2006 08:27 PM
UDF code to find specific text in cell comments, then average cell values bruch04 Microsoft Excel Programming 3 5th Dec 2005 10:01 PM
Determine shape name associated with a specific cell slingsh0t@hotmail.com Microsoft Excel Misc 1 12th May 2005 12:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 PM.