Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm having problems with IF statements in Word

Status
Not open for further replies.

chaft

Technical User
Feb 7, 2008
55
GB
I'm Having a difficulty mastering the IF statements in icrosoft word.

I have two if statements that I want united

I only want one IF statement to present it's answer. In the case of both having the required data to run then I want the second IF statement to have priority.


I have two IF statements that check to see if the person's name is there. If it is not, it displays the job title.
The other statement checks if the person has a clerical title, if not it displays nothing.

But if there IS A CLERICAL title then I want it ONLY to show the CLERICAL title. I don't want it to show the first IF statement.

hope that is kinda clear.
I have the two if statements and they work. But how can I write the adjoining IF statement?








 




Hi,

You have to nest them, like...
[tt]
{ IF Expression1 Operator Expression2 { IF ExpressionA Operator ExpressionB TrueText FalseText } FalseText }


[/tt]


Skip,
[sub]
[glasses]Just got a nuance...
to replace the old subtlety![tongue][/sub]
 
Not sure about word, I don't use it very often but in excel it would be:


Code:
=IF(AND(A2="",B2=""),"",IF(B2="",A2,B2))
Explanation

A2 Holds the Name
B2 holds the position

The first checks to see if both ar empty, then returns an empty string,
Code:
IF(AND(A2="",B2=""),"",

otherwise, if the postiion is empty, return the name.

Code:
IF(B2="",A2

otherwise return the postion.

Code:
IF(B2="",A2,B2))


Again not sure how this wuld fit in word, but may give ideas...



Take it Easy
Man with one chopstick go hungry
 
Please confirm that you are in fact using these If statements within a field. Everyone seems to assume that - and it is most likely - but I would like to be sure.

faq219-2884

Gerry
My paintings and sculpture
 
Hi chaft,

I'm assuming this is for a mailmerge, in which case you could code your IF field tests like:
Code:
{IF«ClericalTitle»= "" {IF«Name»= "" «JobTitle»} «ClericalTitle»}

where 'ClericalTitle', 'Name' and 'JobTitle' are the names of your mergefields.

Cheers

[MS MVP - Word]
 
thanks it worked with your help.

Can't say it was easy.. Microsoft IF statements are REAL pain as I can't seem to copy them into notepad and everytime I have to keep toggling. I wish microsoft would make it easier for nested loops.
 
Hi chaft,

FWIW, it's sometimes much easier to create fields for IF statements via the keyboard (using Ctrl-F9) than via Insert|Field.

For example, with the field coding I posted above, you could start off with the «Name» & «JobTitle» mailmerge fields and two copies of the «ClericalTitle» mailmerge field in your mailmerge document arranged as:
«ClericalTitle», «Name», «JobTitle» «ClericalTitle»
Then you could select the «Name», & «JobTitle» fields and press Ctrl-F9 to wrap them in a new field, then select all of these fields and press Ctrl-F9 again to wrap the lot in a new field, so that you get:
{«ClericalTitle» {«Name» «JobTitle»} «ClericalTitle»}
From there it's a simple matter to type in the expressions required for the IF tests.

Cheers


[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top