473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Contains IF function

63
I am trying to add in a simple IF function that applies only if the cell contains a certain value. Does anyone know of a formula type that would return this - or what syntax I should use with the standard IF function if one is not available

thanks
Jul 30 '07 #1
10 2115
hariharanmca
1,977 1GB
I am trying to add in a simple IF function that applies only if the cell contains a certain value. Does anyone know of a formula type that would return this - or what syntax I should use with the standard IF function if one is not available

thanks

it Should be

Condition
--------------------
If <Condition> Then
<Execute True Part>
Else
<Execute False Part>
End If


Function
------------------------
Dim strReturnValue as String
'Example is in string datatype you can use any VB datatype
strReturnValue = IIF(<Condition>, "Return True", "Return False")
Jul 30 '07 #2
Killer42
8,435 Expert 8TB
I am trying to add in a simple IF function that applies only if the cell contains a certain value. Does anyone know of a formula type that would return this - or what syntax I should use with the standard IF function if one is not available
Not entirely sure I understand the question. But what about nesting your IF functions. For example, let's say you want to do something only if cell A1 = "Q". You could do something like...

IF($A$1="Q",IF(Condition,TruePart,FalsePart),Null)
Jul 30 '07 #3
hariharanmca
1,977 1GB
Not entirely sure I understand the question. But what about nesting your IF functions. For example, let's say you want to do something only if cell A1 = "Q". You could do something like...

IF($A$1="Q",IF(Condition,TruePart,FalsePart),Null)
It would be iif and like
IIF($A$1="Q",IIF(Condition,TruePart,FalsePart),Nul l)

yes, we can work like this.
Jul 30 '07 #4
'iif' is used in access whereas 'if' is used in excel for if you are referring to a cell in excel it would be if(A1=x,do this, do the other)
in access it is exactly the same except that you would use iif.
Jul 30 '07 #5
hariharanmca
1,977 1GB
'iif' is used in access whereas 'if' is used in excel for if you are referring to a cell in excel it would be if(A1=x,do this, do the other)
in access it is exactly the same except that you would use iif.
Of-Course, we can use IIf in Vb 6.0 too. How could there be any doubt.
Jul 30 '07 #6
Killer42
8,435 Expert 8TB
Of-Course, we can use IIf in Vb 6.0 too. How could there be any doubt.
I just took it that we were working in Excel, based on the references to "cell", "formula" and "standard IF function". It does tend to generate confusion though, when people omit relevant information such as the environment in which they are working.

Hint hint, grego9. :)
Jul 30 '07 #7
grego9
63
Apologies - we were working in Excel 2000. Thanks for the help - I'm not sure it has quite answered the question. My problem is trying to find the syntax if the cell contains any of the text in a particular string. So as an example i might be looking for a cell that contains GGG anywhere in it - so this would return the following cells:

CCGGGŁ
GGGDD
and
HHHGGG

So it's really the containing part that is key to the IF Function syntax for me
Jul 31 '07 #8
Killer42
8,435 Expert 8TB
Ah! So you want to know whether any part of the field matches your value. Let's see...

Well, according to the Excel doco (you really should have had a look there - I just looked up IF) there's a technique to "Check if part of a cell matches specific text, and return a value". this sounds like what you're after.

Use the IF, FIND, SEARCH and ISNUMBER functions to do this task.

Example:
=ISNUMBER(FIND("BD",A3)) Checks to see if A3 contains BD.
This will return True or False, so you can then use that as the input to your IF() test. In other words...

=IF(ISNUMBER(FIND(<search-for>,<where-to-search>)),TruePart,FalsePart)
Jul 31 '07 #9
grego9
63
brilliant thank-you - sorry I didn't reply earlier I have been on my hols!
Aug 8 '07 #10
Killer42
8,435 Expert 8TB
brilliant thank-you - sorry I didn't reply earlier I have been on my hols!
No problem. Glad we could help. :)
Aug 9 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Miguel Orrego | last post by:
Hi, I have a variable in an app called GenericTitle which contains text, a persons job title funnily enough. I want to check whether this variable contains the word "director" and if it does,...
3
by: Jason | last post by:
I am having trouble using the CONTAINS function in sql server(enterprise manager). I am typing the following: Select * FROM mytable WHERE CONTAINS(myfield,'mystring') This returns the...
2
by: sprungli | last post by:
My goal is to select some XPath nodes based on whether their values (text) contain a string passed as argument. To achieve this I use the contains() function of XPath in an XpathExpression. For...
2
by: tschulken | last post by:
I am trying to get certain nodes within an xml doc that contain certain text (similar to a SQL LIKE). In doing so I am using the XPATH Contains function and have not been successful. When I run I...
5
by: matt tagliaferri | last post by:
I'm implementing a typed collection class that can't include duplicates. The Add method of the collection class is as follows: Public Function Add(ByVal o As TeamListEntry) As Integer If...
17
by: Tom | last post by:
Is there such a thing as a CONTAINS for a string variable in VB.NET? For instance, I want to do something like the following: If strTest Contains ("A","B", "C") Then Debug.WriteLine("Found...
2
by: Dot net work | last post by:
Hello, My simple code is here: Public Class MyDictionary Inherits System.Collections.DictionaryBase Private Class MyElement Public Overloads Overrides Function Equals(ByVal obj As Object)...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
8
by: Tanzen | last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having come from an VB for Access background, I'm finding it a big learning curve. I have been working through several e-books which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.