ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search (https://www.excelbanter.com/excel-programming/326358-search.html)

tjh

Search
 
Hello,

I am stuck and cannot remember how to do this...

I would like to perform an if statement that:

if (the current cell has a "C" character somewhere within it) then
........Perform an action......
elseif (it does not) then
..........perform another action.......
endif

What statement do I need to use to determine if a "C" is a character
anywhere in the cell. I remember how to use the Left, Right and Mid
functions, but I cannot remember how to use the Search function in this
manner. What would be the best way to go about doing this?

Thank You,


Toppers

Search
 
Hi,
Try this :

Sub test()

Dim stringtosearch As String
Dim stringtofind As String

stringtosearch = "ABCDEFG"
stringtofind = "C"

If InStr(1, stringtosearch, stringtofind) < 0 Then
MsgBox "C found" ' Add found logic.....
Else
MsgBox "C not found" ' Add not found logic ....
End
End If

End Sub

HTH

"tjh" wrote:

Hello,

I am stuck and cannot remember how to do this...

I would like to perform an if statement that:

if (the current cell has a "C" character somewhere within it) then
.......Perform an action......
elseif (it does not) then
.........perform another action.......
endif

What statement do I need to use to determine if a "C" is a character
anywhere in the cell. I remember how to use the Left, Right and Mid
functions, but I cannot remember how to use the Search function in this
manner. What would be the best way to go about doing this?

Thank You,



All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com