Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hello,
I have the following in VBA: If .Cells(X, "K") = "RG" Then .Cells(X, "Q").Value = "TRC" How can I modify this formula to look in column K for a string that contains RG and perform the same function? (i.e., if it contains RG-TRVL or TRVL-RG, then TRC should automatically be placed in column Q)? Thank you. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Thu, 14 Jan 2010 12:25:01 -0800, richzip
wrote: Hello, I have the following in VBA: If .Cells(X, "K") = "RG" Then .Cells(X, "Q").Value = "TRC" How can I modify this formula to look in column K for a string that contains RG and perform the same function? (i.e., if it contains RG-TRVL or TRVL-RG, then TRC should automatically be placed in column Q)? Thank you. Use the InStr function. If it returns a non-zero, your substring is contained in the string. --ron |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Take a look at Like or InStr in VBA's help
if ucase(.cells(x,"K").value) like "*RG*" then or if instr(1,.cells(x,"K").value,"RG",vbTextCompare) 0 then (InStr has a parm that you can specify to ignore case (if you want).) richzip wrote: Hello, I have the following in VBA: If .Cells(X, "K") = "RG" Then .Cells(X, "Q").Value = "TRC" How can I modify this formula to look in column K for a string that contains RG and perform the same function? (i.e., if it contains RG-TRVL or TRVL-RG, then TRC should automatically be placed in column Q)? Thank you. -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
The line
If InStr(.Cells(X, "K"), "RG") 0 Then .Cells(X, "Q").Value = "TRC" should do the trick -- If this helps, please remember to click yes. "richzip" wrote: Hello, I have the following in VBA: If .Cells(X, "K") = "RG" Then .Cells(X, "Q").Value = "TRC" How can I modify this formula to look in column K for a string that contains RG and perform the same function? (i.e., if it contains RG-TRVL or TRVL-RG, then TRC should automatically be placed in column Q)? Thank you. |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Here's part of code that I'd probably set up to do it:
Dim testRange as Range Dim anyTestCell as Range Set testRange = ActiveSheet.Range("K1:" & _ ActiveSheet.Range("K" & Rows.Count).End(xlup).Address) For Each anyTestCell in testRange If Instr(anyTestCell,"RG")0 Then Range("Q" & anyTestCell.Row) = "TRC" End IF Next ' end anyTestCell loop .... more code 'good housekeeping: Set testRange = Nothing .... End Sub "richzip" wrote: Hello, I have the following in VBA: If .Cells(X, "K") = "RG" Then .Cells(X, "Q").Value = "TRC" How can I modify this formula to look in column K for a string that contains RG and perform the same function? (i.e., if it contains RG-TRVL or TRVL-RG, then TRC should automatically be placed in column Q)? Thank you. |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
For you exact statement, I think you could rewrite it this way:
If Instr(.Cells(X, "K"),"RG") 0 Then .Cells(X,"Q").Value = "TRC" End If "richzip" wrote: Hello, I have the following in VBA: If .Cells(X, "K") = "RG" Then .Cells(X, "Q").Value = "TRC" How can I modify this formula to look in column K for a string that contains RG and perform the same function? (i.e., if it contains RG-TRVL or TRVL-RG, then TRC should automatically be placed in column Q)? Thank you. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
search string for number value | Excel Discussion (Misc queries) | |||
How to search a string from the right ? | Setting up and Configuration of Excel | |||
to search for a string and affect data if it finds the string? | Excel Worksheet Functions | |||
Q: search in string | Excel Discussion (Misc queries) | |||
Segregating a Search String | Excel Discussion (Misc queries) |