Additions with variables in VBA - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Additions with variables in VBA (/showthread.php?tid=5235) |
Additions with variables in VBA - Qomplainerz - 07-27-2023 Description: This code calculates the sum of two numbers and displays the result in a message box. Example: Sub SumNumbers() Dim num1 As Double Dim num2 As Double Dim sum As Double num1 = 5 num2 = 3 sum = num1 + num2 MsgBox "The sum of " & num1 & " and " & num2 & " is " & sum & "." End Sub Explanation: This code defines a subroutine named SumNumbers. It declares three variables num1, num2, and sum to hold the values of two numbers and their sum. It then sets the values of num1 and num2 to 5 and 3, respectively. The sum of the two numbers is calculated and displayed in a message box. The Dim statement is used to declare variables. In this case, we use the Double data type to store numbers with decimal places. The & operator is used for string concatenation, combining text and variable values in the message box. |