Exercise - Calculate modulo with VBScript

Completed

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.

  1. Launch the Power Automate for desktop console and click on the + New flow.

    Screenshot of the Power Automate for desktop.

  2. Name the new flow as Overtime calculator and click Create.

    Screenshot of the Power Automate for desktop Build a flow dialog.

  3. Under Actions search for launch.

    Search for launch under actions.

  4. Add the Launch Excel action to the workspace and configure it to launch the Employees.xlsx file.

    Screenshot of the Power Automate for desktop Launch Excel action.

  5. Under Actions search for get first and double-click on Get first free column/row from Excel worksheet.

    Screenshot of the Power Automate for desktop Get first search in actions.

  6. Use the Get first free column/row from Excel worksheet action to find the first free row in the file.

    Screenshot of the Power Automate for desktop Get first free column/row from Excel worksheet action.

  7. Under Actions search for loop and double-click on it.

    Screenshot of the Power Automate for desktop Loop action in search results.

  8. In Start from, manually type in 1. In End to, click on {X}, then select FirstFreeRow.

    Screenshot of the first free row variable.

  9. Update the End to formula as shown below. Finally, in Increment by, add 1.

    Screenshot of the Power Automate for desktop Loop action.

  10. 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.

    Screenshot of the Power Automate for desktop Read from Excel worksheet action.

  11. Under Actions search for run vbs and drag-and-drop Run VBScript below Read from Excel worksheet

  12. In VBScript to run type result=, then select the {X} and select TotalHours and then Save.

    Screenshot of the Power Automate for desktop Run V B Script action.

  13. Complete the rest of the script as shown below.

    Screenshot of the Power Automate for desktop Run VBScript action.

  14. This is a good time to save the flow you have built so far.

    Screenshot of the save flow button.

  15. 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.

    Screenshot of the Power Automate for desktop Convert text to number action.

  16. Use a Write to Excel worksheet action to write the numerical value in the current row's third cell.

    Screenshot of the Power Automate for desktop Write to Excel worksheet action.

  17. Outside the loop, add a Close Excel action to save and close the file.

  18. Save the flow and then run it to test that every action works as expected.

    Screenshot of the Power Automate for desktop final flow and the save and run button.