How to do "If cell contains" in VBA
-
Monday, September 07, 2009 1:37 PMHi,
I'm looking for the code to do an if statement when a cell contains "CHECKED OUT"
I have been using the code below but of course it reads the whole contents of the cell and the cell with say CHECKED OUT by ...
If ActiveSheet.Range("C6").Value = "CHECKED OUT"
Thanks,
Richard
All Replies
-
Monday, September 07, 2009 1:49 PM
Hi, you need to use the INSTR function e.g.
If INSTR(1,ActiveSheet.Range("C6").Value , "CHECKED OUT")>0 then- Marked As Answer by LWCARAB Monday, September 07, 2009 3:19 PM
-
Monday, September 07, 2009 1:57 PM
ADG already got you fixed but i will post this anyway. may help in other ways.
Dim celltxt As String
celltxt = ActiveSheet.Range("C6").Text
If InStr(1, celltxt, "CHECKED OUT") Then
MsgBox ("found it")
Else
MsgBox ("no")
End If
FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial- Marked As Answer by LWCARAB Monday, September 07, 2009 3:19 PM
-
Monday, September 07, 2009 2:16 PMThanks, that did just what I wanted!

