Exercise - Calculate modulo with VBScript

Completed

In this exercise, you create a flow that calculates how many overtime hours employees work. 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 desktop app console and select + New flow.

    Screenshot of the Power Automate desktop app.

  2. Name the new flow Overtime calculator and select Create.

    Screenshot of the Power Automate desktop app 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 desktop app Launch Excel action.

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

    Screenshot of the Power Automate desktop app 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 desktop app Get first free column/row from Excel worksheet action.

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

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

  8. In Start from, type 1. In End to, select {X}, and then select FirstFreeRow.

    Screenshot of the first free row variable.

  9. Update the End to formula as shown in the following image. In Increment by, add 1.

    Screenshot of the Power Automate desktop app Loop action.

  10. Under Actions, search for read from excel. You can either double-click Read from Excel worksheet or drag and drop it between Loop and End.

    The action reads the cell that contains the current employee's total working hours.

    Note

    In Variables produced, double-click ExcelData and change the text to TotalHours.

    Screenshot of the Power Automate desktop app 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=, select the {X}, and select TotalHours. Then select Save.

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

  13. Complete the rest of the script as shown in the following image.

    Screenshot of the Power Automate desktop app Run VBScript action.

  14. Save the flow you 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 desktop app 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 desktop app 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 desktop app final flow and the save and run button.