Word if statement example

SharePoint Server Subscription Edition SharePoint Server 2019 SharePoint Server 2016 SharePoint Server 2013 SharePoint Server 2013 Enterprise SharePoint in Microsoft 365 SharePoint Foundation 2010 SharePoint Server 2010 SharePoint in Microsoft 365 Small Business More…Less

Returns one value if a condition you specify evaluates to TRUE and another value if it evaluates to FALSE. Use IF to conduct conditional tests on values and formulas.

Syntax

IF(logical_test,value_if_true,value_if_false)

Logical_test     is any value or expression that can be evaluated to TRUE or FALSE. For example, [Quarter1]=100 is a logical expression; if the value in one row of the column, [Quarter1], is equal to 100, the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE. This argument can use any comparison calculation operator.

Value_if_true     is the value that is returned if logical_test is TRUE. For example, if this argument is the text string «Within budget» and the logical_test argument evaluates to TRUE, then the IF function displays the text «Within budget». If logical_test is TRUE and value_if_true is blank, this argument returns 0 (zero). To display the word TRUE, use the logical value TRUE for this argument. Value_if_true can be another formula.

Value_if_false     is the value that is returned if logical_test is FALSE. For example, if this argument is the text string «Over budget» and the logical_test argument evaluates to FALSE, then the IF function displays the text «Over budget». If logical_test is FALSE and value_if_false is omitted, (that is, after value_if_true, there is no comma), then the logical value FALSE is returned. If logical_test is FALSE and value_if_false is blank (that is, after value_if_true, there is a comma followed by the closing parenthesis), then the value 0 (zero) is returned. Value_if_false can be another formula.

Remarks

  • Up to seven IF functions can be nested as value_if_true and value_if_false arguments to construct more elaborate tests. See the last of the following examples.

  • When the value_if_true and value_if_false arguments are evaluated, IF returns the value returned by those statements.

  • If any of the arguments to IF are arrays, every element of the array is evaluated when the IF statement is carried out.

Example set 1

C
ol1

Col2

Col3

Expense

Formula

Description (Result)

50

=IF([Expense]<=100,»Within budget»,»Over budget»)

If the number is less than or equal to 100, then the formula displays «Within budget». Otherwise, the function displays «Over budget». (Within budget)

23

45

89

50

=IF([Expense]=100,SUM([Col1],[Col2],[Col3]),»»)

If the number is 100, then the three values are added. Otherwise, empty text («») is returned. ()

Example set 2

ActualExpenses

PredictedExpenses

Formula

Description (Result)

1500

900

=IF([ActualExpenses]>[PredictedExpenses],»Over Budget»,»OK»)

Checks whether the first row is over budget (Over Budget)

500

900

=IF([ActualExpenses]>[PredictedExpenses],»Over Budget»,»OK»)

Checks whether the second row is over budget (OK)

Example set 3

Score

Formula

Description (Result)

45

=IF([Score]>89,»A»,IF([Score]>79,»B», IF([Score]>69,»C»,IF([Score]>59,»D»,»F»))))

Assigns a letter grade to the first score (F)

90

=IF([Score]>89,»A»,IF([Score]>79,»B», IF([Score]>69,»C»,IF([Score]>59,»D»,»F»))))

Assigns a letter grade to the second score (A)

78

=IF([Score]>89,»A»,IF([Score]>79,»B», IF([Score]>69,»C»,IF([Score]>59,»D»,»F»))))

Assigns a letter grade to the third score (C)

In the preceding example, the second IF statement is also the value_if_false argument to the first IF statement. Similarly, the third IF statement is the value_if_false argument to the second IF statement. For example, if the first logical_test ([Score]>89) is TRUE, «A» is returned. If the first logical_test is FALSE, the second IF statement is evaluated, and so on.

The letter grades are assigned to numbers using the following key (assuming use of integers only).

If Score is

Then return

Greater than 89

A

From 80 to 89

B

From 70 to 79

C

From 60 to 69

D

Less than 60

F

Need more help?

This is an advanced article for creating Document Automation templates that use conditional statements. It allows you to create a template which has information that changes based on the values of different merge fields.

For general assistance with Document Automation, see here:

  • What is Document Automation?
  • Document Automation: Creating a Template
  • Document Automation: Uploading Templates and Generating Documents

Important Note: Due to the order in which MS Word updates fields, templates with conditional statements work best when generating PDF documents with Document Automation.  If you want to use your conditional templates to generate MS Word documents, please follow the troubleshooting steps HERE.

Contents

Understanding Conditional Statements
     What is a Conditional Statement
     Expressions
     Operator
     TrueText and FalseText
     Putting it all Together
Adding Conditional Fields to a Word Template
     Limitations and Syntax
Tips and Examples of Useful Conditional Statements
     Using Clio Checkboxes to Determine what is Displayed
     Using Clio Picklists to Determine what is Displayed
     Nesting Conditional Statements (Multiple Conditions)
     Adding Line Breaks to TrueText and FalseText
Troubleshooting Document Generation in MS Word

Understanding Conditional Statements in MS Word

What is a Conditional Statement?

In the most basic language, a conditional statement says that: if some condition is applicable, then do something. 

Conditional statements follow the general format: IF this THEN that or ELSE some other thing. For example:

  • IF the trust balance is 0, THEN display a message asking for another prepayment, ELSE display a thank you message
  • IF custom_field_1 is true, THEN display custom_field_2, ELSE display custom_field_3

In MS Word, the conditional statement format looks like this:

IF Expression1 Operator Expression2 «TrueText» «FalseText«

Expressions

Expressions are something with a value. In the example of Document Automation, a merge field tag can be an expression. A conditional statement has 2 Expressions, or values, that are compared in order to determine what information is displayed.

Note that Expressions (or merge field tags) that have a value that is in plain text need to be surrounded by quotation marks; but Expressions that have a numeric value should not be surrounded by quotation marks.

To indicate that a value is empty (specifically for the second Expression), use 2 quotation marks with nothing between them «» in place of the second Expression. 

Examples of Merge Tags with a Text Value
(surround these with quotes)

<< Matter.Number >>
<< Matter.Description >>
<< Matter.ResponsibleAttorney >>
<< Matter.Client.Name >>

Examples of Merge Tags with a Numeric Value
(do not surround these with quotes)

<< Matter.TrustBalance >>
<< Matter.OperatingBalance >>
<< Matter.Client.TrustBalance >>
<< Matter.Client.OperatingBalance >>
<< Matter.Client.PaymentProfile.InterestRate >>
<< Matter.Client.PaymentProfile.GracePeriod >>

Operator 

The operator defines how the expressions relate to each other. For example, are they equal/the same, or not? 

= Equal to Use with both text and numeric Expressions
<> Not equal to Use with both text and numeric Expressions
> Greater than Use with numeric Expressions only
< Less than Use with numeric Expressions only
>= Greater than or equal to Use with numeric Expressions only
<= Less than or equal to Use with numeric Expressions only

TrueText and FalseText 

TrueText refers to the text that will be displayed if the condition (relationship between the expressions) is satisfied.

FalseText refers to the text that will be displayed if the condition is NOT satisfied (this is the ELSE part of the statement).

TrueText and FalseText statements should be surrounded by quotation marks. 

If you want either the TrueText or FalseText to be empty (to not display anything), just use empty quotation marks «».

You can also use Clio merge field tags in your TrueText and FalseText.

Putting it all Together

Putting together all of the elements detailed above, a conditional statement that will display a message asking for a prepayment funds if the client’s trust balance is zero can look something like this:

For more information on composing conditional statements for use in MS Word, click HERE.


Adding Conditional Fields to a Word Template

To add a conditional field in MS Word, ensure that your text cursor is located in your document where you want the conditional text to display, then click on the «Insert» tab then click on the «Quick Parts» icon in the «Text» group (Newer versions of Word will not have the Quick Parts icon, but they will have the Field icon) . 

In the Quick Parts menu, click on the «Field» option. 

In the «Field» window, scroll through the «Field names» list and select «If». Enter your conditional statement into the «Field codes» text area then click «OK».

In your document, you will likely see the FalseText of your conditional statement. That is because the Word document doesn’t know the value of your Clio merge field tags before Document Automation takes place. To make fields in your document stand out more clearly, you can change how fields are displayed in your Word document. 

Open the Word Options window by pressing Alt+f+t on your keyboard. In the Options window, click «Advanced» from the side panel then scroll down to the section «Show document content». There are 2 options here to help you quickly identify fields in your document: «Show field codes instead of their values» and «Field shading: Always».

Limitations and Syntax

  • The «Field codes» field has a character limit of 255 (including spaces), so the specific steps detailed above are only useful for displaying short pieces of information. To display longer text, you have a couple of options.

    1. Save the field to your document then paste in the longer text:

      Start by entering the outline of your conditional statement into the «Field» window without entering the long TrueText or FalseText, then click «OK» to add the field to your document.
      For example: 

      IF «<< Matter.Status >>» = «Open» «» «»

      If the field code is not already visible in your document (if you are seeing the field’s Expression or FalseText instead), right click on the field and select «Toggle Field Codes». With the field code visible, click into the TrueText or FalseText quotes (where the long piece of text applies) then start typing in the text or paste it from another source.

    2. Use Clio Custom Fields containing the long text that you want to pull in to your document. 
      For example:

      IF «<< Matter.Status >>» = «Open» «<< Matter.CustomField.1 >>» «<< Matter.CustomField.2 >>» 

  • Conditional statements do not support special characters or quotation marks in the text that you use for your TrueText or FalseText.
    For example, the following statement will not work properly:

IF «<< Matter.CustomField.Pleading >>» = «guilty» «The defendant pleads «guilty».» «The defendant pleads «not guilty»

To display text that contains quotation marks or special characters, you will have to add that information to Clio Custom Fields then use those merge fields for your TrueText and FalseText.   


Tips and Examples of Useful Conditional Statements

Using Clio Checkboxes to Determine what is Displayed

Using Clio Custom Fields, you can add custom checkboxes to your Contacts and Matters that can be used to determine what is displayed in your generated document. To reference a Clio checkbox, use the merge field tag in the place of the first Expression. The second Expression will be either «true» or «false» — «true» if the box is checked, «false» if the box is not checked. 

For example:

IF «<< Matter.CustomField.Checkbox >>» = «true» «This box is checked.» «This box is not checked.»

Using Clio Picklists to Determine what is Displayed 

Using Clio Custom Fields, you can add custom picklists to your Contacts and Matters that can be used to determine what is displayed in your generated document. To reference a Clio picklist, use the merge field tag in the place of the first Expression. The second Expression will match the custom option that should be selected.

For example:

IF «<< Matter.CustomField.Picklist >>» = «option1» «You selected option 1.» «You did not select option 1.»

To accommodate picklists with more than 2 options, see the section below, «Nesting Conditional Statements».

Nesting Conditional Statements (Multiple Conditions)

You can create conditional statements that consider multiple scenarios/conditions. «Nesting» a condition within another condition requires a few extra steps and specific syntax to work properly.

For example, to write a conditional statement that looks for all possible responses from a picklist with 4 options, follow these steps.  

  1. Click in your document where you want the condition to go, then press Ctrl+F9 (on a Windows computer) on your keyboard to insert a blank field (2 curly brackets ). If you have a Mac, click the Insert tab > Field, under Field names choose «If», then click OK. If it says «Error! Missing test condition.», highlight that phrase, right-click your mouse and choose Toggle Field Codes.
  2. Within the brackets (the «* MERGEFORMAT» part of «{ IF * MERGEFORMAT}» syntax can be removed), type a space then begin typing the outline of the conditional statement (note that it is always important to have a space between all curly brackets and any other characters in your statement).

    The basic outline of this conditional statement should look like this:

  3. Click between the FalseText quotation marks then press Ctrl+F9 on your keyboard (on a Mac, click the Insert tab > Field, under Field names choose «If», then click OK. If it says «Error! Missing test condition.», highlight that phrase, right-click your mouse and choose Toggle Field Codes) to insert another blank field. This blank field is where you will type in another conditional statement that will look for the second option in the list.
  4. Within the brackets of the second/nested field, type in the outline of the conditional statement to look for option 2.

    Your nested conditional statement should now look like this:

  5. Repeat steps 3 & 4 but his time click between the FalseText quotation marks for the second condition before pressing Ctrl+F9 on your keyboard (on a Mac, click the Insert tab > Field, under Field names choose «If», then click OK. If it says «Error! Missing test condition.», highlight that phrase, right-click your mouse and choose Toggle Field Codes). 
  6. Continue adding new conditional statements to the FalseText of each option condition until you have added the last option. In the FalseText for the last option, just enter the text or field that you would like to display if none of the conditions are satisfied. 

    The complete statement should look something like this:

    Or, for clearer visibility, the nested conditions can be colour coded as such:
    { IF «<< Matter.CustomField.Picklist >>» = «option1» «You selected option 1.» «
    { IF «<< Matter.CustomField.Picklist >>» = «option2» «You selected option 2.» «
    { IF «<< Matter.CustomField.Picklist >>» = «option3» «You selected option 3.» «You selected option 4.» }» }
    » }

Adding Line Breaks to TrueText and FalseText

If you need to break up the text that you are using for your TrueText or FalseText, you can add line breaks by directly modifying the field codes in your document. 

If the field code is not already visible in your document (if you are seeing the field’s Expression or FalseText instead), right click on the field and select «Toggle Field Codes».

You will now see the entire field code and be able to edit the text and add line breaks.

Click into the text where you want the line breaks to go then press Shift+Enter to add a soft break.  

Troubleshooting Document Generation in MS Word

Due to limitations in how MS Word updates fields, you may not see your conditional fields updated appropriately after generating a document through Clio. In most cases, you will have to open the newly generated Word document and manually update all fields in order to see the appropriate values of your conditional statements. To do so, select all content in your document (using Ctrl+a) then hit F9 on Windows (or fn+F9 on a Mac) on your keyboard to update all fields in your document. You will then have to save the document and re-upload it to Clio, unless you are editing the document using Clio Launcher.

If updating the fields in your generated Word document does not fix the problem, then you will need to determine if the conditional field has any errors. To do that, use your template to generate a PDF in Clio, then view the PDF. If the field appears correctly on the PDF, then you can be assured that your conditional field is working properly. If the field is not appearing correctly in the PDF, then you will need to go back to your template and look for problems in the field construction and syntax.

If Statements / If Fields / Comparison Statements

IF statements (also called IF fields) allow you to compare two values and display document content based on the result of the comparison. When used in a Word template, IF statements are especially useful for comparing the values of Composer merge fields and then displaying the appropriate content.

Example use cases:

  • If an Account’s billing country is not in the United States, display information about international shipping terms. Otherwise, show domestic shipping terms.
  • If a Contact’s mailing address is blank, show the billing address from his related Account. If it’s not blank, show the Contact’s mailing address.
  • If an Opportunity’s amount is greater than $10,000, show information about a complimentary service package. If not, show nothing.

Nested IF statements in Word, where the else value is another IF statement, will work with Conga Composer but are not recommended. Conga Technical Support will not assist with nested IF statements. Conga highly recommends evaluating nested IF statement logic using Salesforce formula fields and then merging the formula field values into the document.

Watch this video on How to Add IF Statements to Templates.

Create IF Statements in a Word Template

IF statements can use Word merge fields or text-based merge fields, with one exception: the IF statement itself must be a Word merge field. This means that all the fields inside or around the IF statement can be either Word or text-based merge fields, but again, the IF statement itself must be a Word merge field.  Following are examples of both types of syntax.

Syntax

{IF "Expression 1" Operator "Expression 2" "TrueValue" "FalseValue"}

Below is a very basic example using Word merge fields as Expressions. The single braces ({ }) on either end of the IF statement indicate the beginning and end of a Word merge field when the field codes have been toggled open.

{IF "{{Opportunity_Amount}}" > "100000 "Big Deal Opptye" "Normal Oppty"}

Components of an IF Field

Expression1 & Expression2:

  • Both Expression1 and Expression2 represent fields and values that you want to compare.
  • Expressions are usually Word or text-based merge fields, text strings, or numbers. Expression1 and Expression2 should be surrounded with quotation marks («»).

Operator

  • A comparison operator. There is always a space before and after the operator.
  • Supported operators:

TrueValue & FalseValue

  • Content that is shown when the comparison is true (TrueValue) or false (FalseValue). Each must be surrounded with quotation marks.

If the content of your TrueValue or FalseValue contains quotation marks ( “ or ” ), you need to replace those quotes with two pairs of single quotation marks (‘’ ‘’ instead of “ ”). Otherwise, Word will consider the first quotation mark from your merged data as the end of your text string and the IF statement will not work.

Creating an IF Field — Conga Best Practices

It is important to follow best practices to ensure the stability and sustainability of your IF statements. In the example below, we will show in detail the best practice method for creating IF statements.  We will also show the syntax for both Word merge field and text-based merge fields.

Example scenario: If the Opportunity Amount is greater than $10,000, show information about a complimentary service package. If it’s not, do not show anything.

We recommend the following approach:

Procedure Step Result
Create a traditional merge field with a placeholder name. «IF_Amount>10000»
Open the merge field by toggling field codes. {MERGEFIELD IF_Amount>10000 * MERGEFORMAT}
Delete the contents of the field, entering IF instead. {IF}
Add Expression1 to the IF field. In our example, Expression1 is the Opportunity Amount field.

Word

{IF “«OPPORTUNITY_AMOUNT»”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}”}

Insert your Operator. We’re using greater than (>).

Word

{IF “«OPPORTUNITY_AMOUNT»” >}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” >}

Insert Expression2. Our example is $10,000.

Word

{IF “«OPPORTUNITY_AMOUNT»” > “10000”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” >  “10000”}

Insert TrueValue. Our example is a merge field that displays the details of a complimentary service package.

Word

{IF “«OPPORTUNITY_AMOUNT»” > “10000” “«OPPORTUNITY_SERVICE_PACKAGE»”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” > “10000” “{{OPPORTUNITY_SERVICE_PACKAGE}}” }

Insert FalseValue. In our example, we don’t want to display anything if the Opportunity Amount is less than $10,000, so our FalseValue is null.  This is represented by a pair of quotation marks.

Word

{IF “«OPPORTUNITY_AMOUNT»” > “10000” “«OPPORTUNITY_SERVICE_PACKAGE»” “”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” > “10000” “{{OPPORTUNITY_SERVICE_PACKAGE}}”  “”}

Our finished IF field looks like this:

Word
{IF “«OPPORTUNITY_AMOUNT»” > “10000” “«OPPORTUNITY_SERVICE_PACKAGE»” “”}

Text-based
{IF “{{OPPORTUNITY_AMOUNT}}” > “10000” “{{OPPORTUNITY_SERVICE_PACKAGE}}”  “”}

An IF statement that is toggled open should look exactly like the examples above when it is completed.  When initially creating the IF statement, Word will include the following text at the end: * MERGEFORMAT. This text needs to be removed to ensure the IF statement renders consistently.

When we toggle the field codes closed, the IF statement will revert to the Word merge field with the placeholder name:

«IF_Amount > 10000»

Using the IF statement we just created, let’s consider an example:

The Merge Nation Opportunity has an amount of $25,000. Once we merge the Composer template that uses our IF statement, our merged document will look like this:

We are showing the value of the OPPORTUNITY_SERVICE_PACKAGE field since that is our TrueValue.

Now let’s say we use a different Opportunity called Merge Republic, which only has an amount of $8,000. Our merged document will show nothing («»), since that is our FalseValue.

Warnings

  • Checkbox fields: Although the Composer View Data Workbook and the Template Builder show the values of checkbox fields as TRUE and FALSE, those values do not work in an IF statement. Change your value from TRUE to True.
    Example: {IF "<<Checkbox_MergeField>>" = "True" "Yes" "No"}
  • Tables: IF statements placed inside a table row cannot hide the table row when the statement evaluates to show nothing.  You will instead have a blank table row. Word IF statements cannot be used to hide rows within a table.
  • IF statements do not work in a Conga Email template.

Word IF Then Else Rule (Mail Merge) Insert Fields

Sep 03, 2015 in Mail Merge

Previously in the article Word IF Then Else Rule (Mail Merge) I’ve explained how you can use the If Then Rule in Mail Merge. In that article the If Then Else Field would insert a text string based on the result of the comparison.

In this article I will explain how you can insert Field Values rather than Text Strings using the If Then Else Rule.


Example:

Assume you are sending letters to 100 recipients. In the Recipient List created for the recipients, there is an Age Field. What we want to do, is to compare the Age Field with the value 18.

  • If the recipients is older than 18 years, then we want the Age to be displayed
  • But if the recipient is younger than 18 years, we want the Text String “Under 18′ to display.

This will be the letter sent out to a 25 year old:

25 Year old Letter

and this will be a letter sent out to a 14 year old:
Under 18 Letter


Step 1:

Follow the same steps explained in the article Word IF Then Else Rule (Mail Merge).


Step 2:

After completing step 1, press Alt+F9. This is what you will see:
AltF9

The top part is the Greeting Line Field (which is irrelevant to our discussion):
Greeting Line Field
Under that line you will see this:
IF Then Else
This is the If Then Else Field:

{ IF { MERGEFIELD Age } > 18 "Over 18" "Under 18" }


The If Then Else Field:

As you can see the If Then Else Field has 3 parts:

If Statement:

This part compares the Age Field with the value 18:

IF { MERGEFIELD Age } > 18 

Result If True:

This is what will be displayed if the If Statement returns True:

"Over 18"

Result If False:

This is what will be displayed if the If Statement returns False:

"Under 18"

What we need to do is to change the Result If True value to { MERGEFIELD Age }:

{ IF { MERGEFIELD Age } > 18 { MERGEFIELD Age } "Under 18" }

By doing this, when the result of the If Statement is true, the Age of the recipient will be displayed.


Step 3:

As explained in the previous section we need to replace the text "Over 18" with the Age Field. In order to do this select and delete the text "Over 18":
Select
Deleete
While the cursor is still in that location insert the Age Field:
Insert Age Field
Insert Age Field 2
Press Alt+F9 to return the normal view:
Result
Result 2
You can download the sample file used in this article from the link below:

  • Insert Field.Zip

See also:

  • Word, Mail Merge
  • Word IF Then Else Rule (Mail Merge)
  • Word Insert Merge Field (Mail Merge)

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

Conditional Mail Merge in MS Word

Microsoft Word provides basic personalization options for mail merges using merge fields. What if you want to apply more advanced personalization in a Word mail merge (beyond the basic first name/last name changes) or include conditionally formatted content in the merge fields? You can accomplish that with conditional mail merge rules in Microsoft Word.

Unlike Excel, there is no conditional formatting button in Microsoft Word. In addition, when sending out emails, MS Word does not preserve the formatting of MS Excel data files. However, you may employ an IF…THEN…ELSE rule to modify formatting and replace text/paragraphs depending on the conditions you define. Conditional mail merge allows you to change the content of your emails based on specific criteria or variable data in your excel data file, such as gender, client sector, purchase date, and so on.

Conditional mail merge capabilities in Microsoft Word are limited and need strong software expertise to set up. In addition, if you make a small error, you’ll run into a slew of formatting issues.

In this article, we’ll show you how to set up a conditional mail merge in MS Word correctly, as well as the most common mistakes to avoid. We’ll also go through a simple method for hyper-personalizing your emails using GMass.

How to Insert Conditional Content (If…Then…Else) in Word Mail Merge Fields

In Microsoft Word, the IF function is enclosed in curly braces. It begins with a condition and then contains the action to perform if true, as well as the action to take if false, as shown below:

{ IF Condition “Truetext” “Falsetext”}

Examples:

{ IF { MERGEFIELD Gender } = “Male” “Mr.” “Ms. }

{ IF { MERGEFIELD Industry } = “Recruiting” “hope the recruiting business is going well, and you’re placing lots of candidates!” “hope things are going well for you.”}

Note: In Microsoft Word, these curly braces must be placed using an If…then…else rule as shown below. Alternatively, you may use the Ctrl+F9 key combination to add them. The conditional formatting will not work if the curly braces are entered manually.

Here’s how to implement conditional mail merge in MS Word:

1. Open MS Word > Go to Mailings tab

2. Click Start mail merge and choose Letters

3. Select the Insert Merge Field option from the dropdown menu to insert merge fields.

4. Select where you want the conditional text to be placed.

5. Press Alt + F9 so you can see the field codes

6. To apply conditional formatting, Go to Mailings > Rules > If…Then…Else and a pop-up box will open

If..then..else.. option

7. In the Field name dropdown select the desired field from the data source (MS Excel File) you want to use for conditional text

if...then...else... popup

8. In the Comparison box, choose a method for comparing the data value.

9. In the Compare to box, type in the comparison value

10. In the Insert this text box, enter the content that appears in the document when the comparison criteria is met.

11. In the Otherwise insert this text box, type in the words that would be included in the document when the comparison criteria is not met

12. Select OK.

13. If you want to apply conditional formatting manually, you need to use Ctrl+F9 to add the curly braces and the field codes.

Note: Don’t use spaces in your field names.

Formatting the Conditional Text in Word Mail Merge

When you perform a merge mail in Microsoft Word, the formatting of an MS Excel data file is lost. You must edit the field code if you want to change the color of the conditional text. For example, if you want to change the color of “Truetext” to blue, modify the field code as follows:

{ IF { MERGEFIELD Industry } = “Recruiting” “hope the recruiting business is going well and you’re placing lots of candidates!” “hope things are going well for you.”}

Nesting Conditional Statements / Multiple If- Else Conditions in Word Mail Merge

If you want to use multiple IF statements, simply add more IF functions in the field code, as shown below:

{ IF Condition1 “Truetext” { IF Condition2 “Truetext” “Falsetext” }}

{ IF { MERGEFIELD Industry } = “Recruiting” “hope the recruiting business is going well and you’re placing lots of candidates!” { IF { MERGEFIELD Industry } = “Sales” hope your sales are high and you’re closing deals left and right! “hope things are going well for you.”}}

Problems with Conditional Formatting in Word Mail Merge

  1. If you have more than one condition or wish to perform more complex mail merge personalization, the procedure gets considerably more difficult.
  2. You can not simply type the curly braces {}; MS Word must add these. You can only create a blank field by pressing Ctrl+F9. If you type the curly braces manually, the conditional formatting won’t work.
  3. The text you use for your TrueText or FalseText should not include any special characters, such as slashes (/), Inverted Commas, Quotation Marks, brackets ([]), or braces ({). This is because MS Word will not output them during the mail merge. 
  4. If any of the “IF” fields are blank during mail merge, MS word won’t be able to suppress them. As a result, you will see additional blank lines or inconsistent output in your mail merge letters. To eliminate them, you need to add a “b” after the merge field.
  5. If you have any hyperlinks in the conditional text, those will not be outputted by the simple If…Then…Else… rule.

Conditional Text Automation with GMass and Gmail

GMass has created a simple solution to send personalized mail merges using Gmail that eliminates the typical conditional formatting and other mail merge issues associated with MS Word. With GMass, you can use If/Then and other statements in your Subject and Message to hyper-personalize content based on any criteria you have associated with each email address. Read our full guide on conditional content for personalized emails.

Conditional mail merge in Gmass

Along with this, you can also:

Personalize links and URLs for each recipient, including anchor links without link breakage that can otherwise occur in the Compose window.

Personalize attachments by sending individual images, invoices, or documents to each recipient in a mass email.

Personalize images for each recipient to include a different team logo, pet breed, or astrological sign, etc.

Personalize large blocks of text according to the needs of each recipient, such as a different promotional offer for different levels of customers, or for customers in different zip codes.

Send your campaign to a personalized CC or BCC address for each recipient to keep the associated salesperson or distributor in the loop according to their respective territories or accounts.

Personalize the To header of each individual email so that your contact’s First and Last name appear as part of the To line instead of just their email address.

For our full set of personalization documentation see the personalization category page on this blog.

We’ve tried to make GMass as simple to use as possible. It is simple to double-check your personalization before sending your email to all of your recipients. You may use the Send Test button with the Create Drafts option to see instantly what personalization to everyone on your list will look like. Simply select the “Send Test” option and check your Gmail DRAFTS folder. When you’re ready to send your campaign with the red GMass button, don’t forget to switch the Action back to “Send email.”

Conclusion

The Microsoft Word mail merge tool is powerful, but it has certain limits. For example, it isn’t well-equipped to handle complex mail merges or conditional content, resulting in errors and formatting issues that are difficult to troubleshoot. You can use GMass to create hyper-personalized bulk email campaigns using Gmail. With in-depth analytics and automation, you’ll have all you need to easily send, manage, and follow up on your emails. Why not download the GMass Chrome extension today and try it yourself?

Ready to transform Gmail into an email marketing/cold email/mail merge tool?

Only GMass packs every email app into one tool — and brings it all into Gmail for you. Better emails. Tons of power. Easy to use.

TRY GMASS FOR FREE

Download Chrome extension — 30 second intall!
No credit card required

Love what you’re reading? Get the latest email strategy and tips & stay in touch.

For example, this can be useful if you’d like a question label to be omitted from the document, if the associated question isn’t answered. 

or

In either case, if an answer to {{fields.Name}}  is not present, the section My name is {{fields.Name}}. will not be added to the document.

Available Functions and Operators:

Note on null: You can also use null to check if a question is blank.

Notes: 

Other useful examples:

Tables

You can also use if statements across table rows. To do this you just put the start of the if statement in the first column cell and the {% endif %} in the last cell.

e.g. If you had a row of data about our ship that was checked — to hide the whole row if the data is missing you would put {% if fields.ShipChecked %} in the first cell of the row and then the {% endif %} in the last cell of the row.

If {{fields.ShipChecked}} doesn’t have a value, the entire row will not be placed in the document.

Images

Just like text and tables, you can also use if statements to conditionally show images.
For example, after selecting the name of a client, the associated client’s logo can be shown.
In the example template below are 2 potential client logos. 

Blank Spaces

If your template has many if statements, you may see unwanted blank space in your report when some if statements are not active.

Placing the previous {% endif %} and next ‘if statement start’ right next to each other will eliminate unwanted space in your report, as the new line spaces are also considered conditional data inside the if statement.

Repeat Groups:

To conditionally show an entire Repeat Group, use fields. and your Repeat Group name in the if statement.

To conditionally show individual Repeat Group items using an IF statement

(Case sensitive)

{%for products_used_item in fields.Products_Used%}

{% if products_used_item.Product == «Red» %} «Paint House Red» {% endif %}

{% if products_used_item.Product == «Blue» %} «Paint House Blue» {% endif %}

{%endfor%}

Custom Destination Email Subject & Body:

If you would like your Email destination to reflect information from your form, you can use IF statements in the Custom Subject and Custom Body fields within your destination.

Destination Fields:

Email Output (PDF):

Old

02-23-2018, 05:45 AM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default

IF Statement in Word


Hello, I could use some help please. I have a mail merge template that has a field that references secretaries. I need to replace those secretaries names with their bosses names. We have approximately 20 secretaries.

Is I possible to create an IF statement to do this in Word 2010? An example of what I tried so far and it worked somewhat but it still leaves the secretaries name instead of replacing it with the manager’s name, plus I can only do one string . . . and it also changed the font to a smaller font.

{IF «Request_Staff_Person» = «Minnie Mouse» «Mickey Mouse»} The results were: Mickey MouseMinnie Mouse.

Any help would be appreciated.

Reply With Quote

Old

02-23-2018, 07:43 AM

Default


You can insert a series of conditional fields (noting the reference to MERGEFIELD
{IF { MERGEFIELD «Request_Staff_Person» } = «Minnie Mouse» «Mickey Mouse»}{IF { MERGEFIELD «Request_Staff_Person» } = «Donald Duck» «Another Mouse»}etc
Use CTRL+F9 for each bracket pair { } and no spaces between the items; but frankly it might be better if you modified the data source to include the appropriate bosses.

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Old

02-23-2018, 08:22 AM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default


Thank you so much, I’ll give this a try. Unfortunately, the managers’ names are not in our database, and I don’t believe there are plans to add them, the best I could do was to modify the source by adding the available field for the secretaries.

One additional question, is there a limit to how many if statements I can run together?

Reply With Quote

Old

02-23-2018, 09:46 AM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default


This did no work for me.

Reply With Quote

Old

02-23-2018, 11:10 AM

Default


Quote:

Originally Posted by nbuckwheat
View Post

***

One additional question, is there a limit to how many if statements I can run together?

There is no limit to the number of IF Fields you can have, so long as they are independent (not nested, one inside the other).

Reply With Quote

Old

02-23-2018, 11:12 AM

Default


The structure that Graham set forth is the correct structure. If you want more help, more information than «it didn’t work for me» is needed.

Here is more information on the IF Field.

Reply With Quote

Old

02-23-2018, 12:07 PM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default


thanks for the link, i’ll try again. a question, I’ve not done this before in Word. . . didn’t even know it was possible. . . I see {MERGEFIELD ….) is this something I would actually type in before I insert the merge field or is it just indicating that the field should be inserted?

Reply With Quote

Old

02-23-2018, 01:48 PM

Default


Properly implemented, the field code demonstrated in Graham’s post will work. At its simplest, you can use either:
{IF{MERGEFIELD Request_Staff_Person}= «Minnie Mouse» «Mickey Mouse»}{IF{MERGEFIELD Request_Staff_Person}= «Donald Duck» «Another Mouse»}
or:
{IF�Request_Staff_Person�= «Minnie Mouse» «Mickey Mouse»}{IF�Request_Staff_Person�= «Donald Duck» «Another Mouse»}

Note: The field brace pairs (i.e. ‘{ }’) for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can’t simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. ‘� �’) are part of the actual mergefields — which you can insert from the ‘Insert Merge Field’ dropdown (i.e. you can’t type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

02-24-2018, 02:19 PM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default


My question is geared more to the actual word «MERGEFIELD» when I insert the merge field into the brackets that I’ve generated by ctrl9, it inserts the merge field but does not include the word MERGEFIELD nor does it include the format with the double arrows as in this example taken from below: �Request_Staff_Person�

Reply With Quote

Old

02-24-2018, 02:58 PM

Default


That merely demonstrates the second of the two examples I posted…

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

02-24-2018, 03:14 PM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default


I don’t see where my question was answered at all. Thank you anyway.

Reply With Quote

Old

02-24-2018, 03:53 PM

Default


Did you actually read my reply???

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

02-24-2018, 04:58 PM

Novice

IF Statement in Word

 

Join Date: Feb 2018

Posts: 9

nbuckwheat is on a distinguished road

Default


Yes Macropod, I did read your answer; however, I don’t believe you read my question . . . I understood what the previous responses were instructing, what I was saying prior to your last response was that no matter what I did . . . the verbiage MERGEFIELD would not appear when I inserted the field into the formula. It only appeared in my result below after I toggled back and forth twice after inserting the field.

For anyone else please that can help with my formula below, I would appreciate it . . .
This is my formula:
{IF{MERGEFIELD Request_Staff_Person}= «Mickey Mouse» «Minnie Mouse»}

This is the result: Mickey Mouse Minnie Mouse. . . instead of replacing Mickey Mouse with Minnie Mouse it is adding it to the same line. I need to replace the original name with the new . . . not add to it.

Many thanks in advance.

Reply With Quote

Old

02-24-2018, 08:52 PM

Default


Quote:

My question is geared more to the actual word «MERGEFIELD» when I insert the merge field into the brackets that I’ve generated by ctrl9, it inserts the merge field but does not include the word MERGEFIELD nor does it include the format with the double arrows as in this example taken from below: �Request_Staff_Person�

If you press Alt+F9 to display field codes, you would see both the MERGEFIELD before the field name. The angle brackets show up when you do not have field codes displayed, instead of the MERGEFIELD and curly brackets.

Reply With Quote

Old

02-24-2018, 09:44 PM

Default


From your description it sounds like you have added the conditional field AFTER the original merge field instead of REPLACING it.

�Request_Staff_Person�{IF{MERGEFIELD Request_Staff_Person}= «Mickey Mouse» «Minnie Mouse»}

The field goes INSIDE the conditional field i.e.

{IF �Request_Staff_Person�= «Mickey Mouse» «Minnie Mouse»}

or with field codes toggled (ALT+F9)

{IF{MERGEFIELD Request_Staff_Person}= «Mickey Mouse» «Minnie Mouse»}
In the case of the latter all bracket pairs are inserted with CTRL+F9

Or you can insert it from the mailmerge tab of the ribbon (Rules)

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Asked
5 years, 6 months ago

Viewed
2k times

in this code, I want to do the following:

  • If the word is finished with a letter M Replace with letter N.
  • If the word ends with a letter N, Replace with letter M.
  • I do not know well using the IF — Then statement.
    Any help would be greatly appreciated.

    Sub find_end()   
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "[nm]>"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .MatchWildcards = True
            Selection.Find.Execute
            With Selection
            If Selection.Find.Found = n Then
                Selection.TypeText Text:=m
            ElseIf Selection.Find.Found = m Then
                Selection.TypeText Text:=n
            End If
    End Sub
    

Martijn Pieters's user avatar

asked Oct 12, 2017 at 17:13

asad41163's user avatar

1

I modified the code found at: Repeating Microsoft Word VBA until no search results found
and it will spin thru a document and replace the last letter (if it’s an ‘m’ or ‘n’) of each word. NOTE there is a ‘loop check in that code that you may want to remove if it’s possible you may find over 2000 m or n’s.

Option Explicit

' The following code adapted from: https://stackoverflow.com/questions/13465709/repeating-microsoft-word-vba-until-no-search-results-found
Sub SearchFN()
    Dim iCount  As Integer
    Dim lStart  As Long
    'Always start at the top of the document
    Selection.HomeKey Unit:=wdStory

    'find a footnote to kick it off
    With Selection.Find
        .ClearFormatting
        .Text = "[nm]>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
        .Execute
    End With

    'Jump back to the start of the document.
    Selection.HomeKey Unit:=wdStory

    'If we find one then we can set off a loop to keep checking
    'I always put a counter in to avoid endless loops for one reason or another
    Do While Selection.Find.Found = True And iCount < 2000
        iCount = iCount + 1

        Selection.Find.Execute

        'On the last loop you'll not find a result so check here
        If Selection.Find.Found Then
            ' Exit if we start back at the beginning
            If Selection.Start < lStart Then
                Exit Do
            End If

            'Reset the find parameters
            With Selection.Find
                .ClearFormatting
                .Text = "[nm]>"
                If Selection.Text = "m" Then
                    Debug.Print "found 'm' at position: " & Selection.Start
                    Selection.Text = "n"
                ElseIf Selection.Text = "n" Then
                    Debug.Print "found 'n' at position: " & Selection.Start
                    Selection.Text = "m"
                End If
                lStart = Selection.Start
'                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = False
                .MatchWholeWord = False
                .MatchKashida = False
                .MatchDiacritics = False
                .MatchAlefHamza = False
                .MatchControl = False
                .MatchByte = False
                .MatchAllWordForms = False
                .MatchSoundsLike = False
                .MatchFuzzy = False
                .MatchWildcards = True
            End With
        End If
    Loop
End Sub

answered Oct 12, 2017 at 18:39

Wayne G. Dunn's user avatar

Wayne G. DunnWayne G. Dunn

4,2801 gold badge12 silver badges24 bronze badges

1

How do I use «OR» in if statements in Word? I’ve tried searching with no luck. I am just trying to compare two fields to check for values. If either of the fields has a value I need to add text.

asked Jul 23, 2019 at 17:15

Admir Salic's user avatar

4

I tried a variation using COMPARE which gives the result I think you’re after — to find out if both fields are empty. I’ve used QUOTE field to combine the results of both fields (so if both fields are empty, this QUOTE will be empty; if either or both contains a value then this QUOTE will have a value). The COMPARE of the QUOTE will return 0 if QUOTE is empty, so the true result for the IF statement is do nothing because both fields are empty, otherwise at least one or both fields contain a value so insert your text.
enter image description here

answered Aug 2, 2019 at 3:07

Tanya's user avatar

TanyaTanya

1,6601 gold badge9 silver badges5 bronze badges

Понравилась статья? Поделить с друзьями:
  • Word in english with all vowels in order
  • Word if function example
  • Word in english that is difficult to pronounce
  • Word if field example
  • Word in english and arabic