How to Set Up an “If Then Else” Statement in Field Calculator

Ever wanted to write an If Then Else statement with a text output, but didn’t know how to format it in field calculator?

This blog shows a simple example of how to do it using VB Script in the Field Calculator.

Below is a fictitious situation that uses an If Then Else statement.
According to Wikipedia Large woody debris (LWD) are the logs, sticks, branches, and other wood that falls into streams and rivers. This debris can influence the flow and the shape of the stream channel.
Since Large Woody Debris are floating objects in the water they have the ability to move with the river. The database below wants to consider Large Woody Debris collected after today’s date as old. Today’s date for this example is 09/12/14.

large woody debris

To do this the Field Calculator for EditType field can be used.
If Then Else statement description: If Large Woody Debris has a date of 9/12/2014 it will be defined as “New”; otherwise define the Large Woody Debris as “Old”; and if the feature is not Large Woody Debris nor have a Date of 9/12/2014 it is defined as “New”.
The following script does this.

Pre-Logic Script Code:
dim x
if [Date] = “9/12/2014” then
x = “New”
elseif [EditorName] = “Large Woody Debris” then
x = “Old”
x = “New”
end if


Below is an explanations for each line.


Line 1 – define the function
Type – dim x

if then statement; If the date is 9/12/2014 then the field calculator will define it as “New”
Line 2 Type – if [Date] = “9/12/2014” then
Line 3 Type – x = “New”

Elseif then statement; If it is not today’s date and it is Large Woody Debris then the field calculator will define it as “Old”
Line 4 Type – elseif [Feature] = “Large Woody Debris” then
Line 5 Type – x = “Old”

else statement; if it doesn’t have today’s date and isn’t Large Woody Debris then the field calculator will define it as “New”
Line 6 Type – else
Line 7 Type – x = “New”

End the Statement
Line 8 Type – end if

Call out the Reclass Function
Under Field Name =
This instance it was Edit Type =
Type – x

4 thoughts on “How to Set Up an “If Then Else” Statement in Field Calculator

  1. This is great! I could see this working well for utilities and determining baseline pipe age, or for manhole, hydrant inspections, etc.

  2. Dear Sir,
    I am writing to ask for your help. I am creating a model by Model Builder, in which first I added a field called “M” in an attribute table of my shape file. Then I wanted to write an IF statement to insert values in my “M” field based on another field called “GRID_CODE”, according to the following rule:

    if “GRID_CODE” is smaller than 300, then “M” field is equal 1;
    if “GRID_CODE” is smaller than 400, then “M” field is equal 2;
    otherwise, “M” field is equal 3.

    I tried writing different statements both in VB and python, but it did not work and I receive an error. Now I am frustrated. my Arcmap version is 10.3.1. can you please help me?


Leave a Reply

Your email address will not be published. Required fields are marked *