-
Solved: HELP!!! Cannot get code to select cells based on specific text within cell.
I have been trying to get the code to work that will select cells from a column that contain specified text. I have no problems when using the autofilter"Contains = BR9" but I need the VBA code in a series of "If Range...Then If" statements to make this selection. I have tried the ones listed below and they either choose all cells that match the first 3 if thens or they choose none of them returning blanks.
Then If Range("AT" & Can) = "=*BR9" Then Range("S" & Can) = "PN9"
Then If Range("AT" & Can) = ">=*BR9" Then Range("S" & Can) = "PN9"
Then If Range("AT" & Can) >= "=*BR9" Then Range("S" & Can) = "PN9"
Then If Range("AT" & Can) = "=*BR9*" Then Range("S" & Can) = "PN9"
Then If Range("AT" & Can) = ">=*BR9*" Then Range("S" & Can) = "PN9"
Then If Range("AT" & Can) >= "=*BR9*" Then Range("S" & Can) = "PN9"
The cells in my range (column AT) contain various text such as "BR9", "BL7.BL8.BR9", and "BL7.BL8". I need to return the value "PN9" in cells in column S that "contain" "BR9"....so far I either get none with PN9 or all have PN9.
HELP!!! Please let me know if I need to provide more of the code.....everything else is working fine.
THANKS!!!
-
[VBA]'I assume can contains a number
If InStr(1, Range("AT" & Can).Value, "BR9") > 0 Then Range("S" & Can).Value = "PN9"
[/VBA]Charlize
ps. one thing I would say is to always define on which workbook and worksheet you are working.
-
SOLVED---
Thanks Charlize!!! That worked....I appreciate the quick reply.
Keith
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules