Exercise - Calculate modulo with VBScript
In this exercise, you'll create a flow that calculates how many overtime hours employees have worked. Consider that a typical working day is eight hours.
Note
Before creating the flow, download the Employees.xlsx file that is required for this exercise. Select Download on the right side of the page and extract the downloaded file to your local computer.
Launch the Power Automate for desktop console and click on the + New flow.
Name the new flow as Overtime calculator and click Create.
Under Actions search for launch.
Add the Launch Excel action to the workspace and configure it to launch the Employees.xlsx file.
Under Actions search for get first and double-click on Get first free column/row from Excel worksheet.
Use the Get first free column/row from Excel worksheet action to find the first free row in the file.
Under Actions search for loop and double-click on it.
In Start from, manually type in 1. In End to, click on {X}, then select FirstFreeRow.
Update the End to formula as shown below. Finally, in Increment by, add 1.
Under Actions search for read from excel. You can either double-click on Read from Excel worksheet or drag-and-drop it between Loop and End.
The action is used to read the cell that contains the current employee's total working hours.
Note
In Variables produced, double-click on ExcelData and change the text to TotalHours.
Under Actions search for run vbs and drag-and-drop Run VBScript below Read from Excel worksheet
In VBScript to run type result=, then select the {X} and select TotalHours and then Save.
Complete the rest of the script as shown below.
This is a good time to save the flow you have built so far.
The return value of the Run VBScript action is a text value. Use a Convert text to number action to convert it to a number.
Use a Write to Excel worksheet action to write the numerical value in the current row's third cell.
Outside the loop, add a Close Excel action to save and close the file.
Save the flow and then run it to test that every action works as expected.