Forum Discussion

stephurso's avatar
stephurso
Copper Contributor
Jan 20, 2022
Solved

Calculating Two Areas in Excel

Hello,   I have a spreadsheet that is broken down into two parts.  The first section of rows is an order like form that users can select products and put down the quantity.  The second section is w...
  • HansVogelaar's avatar
    HansVogelaar
    Jan 20, 2022

    stephurso 

    If you don't see the Developer tab of the ribbon, select File > Options > Customize Ribbon, tick the check box Developer in the list of Main Tabs on the right, and click OK.

     

    Press Alt+F11 to activate the Visual Basic Editor.

    Select Insert > Module.

    Copy the following code into the worksheet module:

    Sub CheckIt()
        If Application.Sum(Range("D11:D65")) = Application.Sum(Range("D72:D120")) Then
            MsgBox "Review Completed", vbInformation
        Else
            MsgBox "Order quantity does not match delivery quantity, please review!", vbExclamation
        End If
    End Sub

    Press Alt+F11 to switch back to Excel.

    On the Developer tab of the ribbon, in the Controls group, select Insert > Button (Form Control).

    Then click on the sheet where you want the button.

    Excel will prompt you to select a macro; choose CheckIt, then click OK.

    Right-click the button and select Edit Text from the context menu.

    Change the caption to Review Order.

    Click outside the button when done.

    (If you need to move or otherwise modify it later on, right-click on the button)

     

    Save the workbook as a macro-enabled workbook (.xlsm), and make sure that you allow macros when you open it.

Resources