Example of using a conditional statement
In this example, you build a bot that prints a message based on whether a cell has a value or is empty. Use the actions from the Excel basic or Excel advanced, If, and Message Box packages.
Prerequisites
Before building this bot, save an empty Excel worksheet to the desktop.
Because this bot does not create a new Excel worksheet, you can use either the Excel basic or Excel advanced packages.
Note: All of the actions must be from the same package.
Procedure
-
Open a new bot.
-
On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create new > Bot.
- Enter a bot name and click Create and edit.
-
On the left panel, click Automation.
-
Use the Open
action from the Excel basic or the Excel advanced
package to open the Excel sheet.
- Double-click or drag the Open action.
- Enter a session name.
- Click Browse to provide the file path to the empty Excel worksheet on the desktop.
-
Use the Get single cell
action to assign the value of a cell to a string variable.
- Double-click or drag the Get single cell action from the same package that you used for the Open action.
- Provide the session name that you used in the Open action.
- Select the Active cell option.
-
In the Store cell contents to field, create the
variable
Output
.
-
Use the If
action to configure the conditional statement.
- Double-click or drag the If action.
- Select String from the Condition drop-down list.
-
In the Source value field, insert the variable
Output
. - Select Equals to as the Operator.
- Leave the Target value field empty.
-
Insert a Message box into the If container.
- Drag the Message box action.
- In the Enter the message to display field, enter Cell is empty.
-
Use the Else and Message box
actions to configure the alternative sequence of actions.
- Drag the Else action next to the If action.
- Drag the Message box action into the Else container.
- In the Enter the message to display field, enter Cell is not empty.
- Click Save.
-
Run the bot.
As the bot runs, the message box appears with the message Cell is empty.
- Enter a value into the cell located at A1 in the Excel sheet and save the sheet.
-
Run the bot.
As the bot runs, the message box appears with the message Cell is not empty.