Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate the average of three numbers in VBA
#1
Example:

Sub CalculateAverage()
    Dim num1 As Double
    Dim num2 As Double
    Dim num3 As Double
    Dim average As Double

    num1 = 5
    num2 = 3
    num3 = 7

    average = (num1 + num2 + num3) / 3

    MsgBox "The average of " & num1 & ", " & num2 & ", and " & num3 & " is " & average & "."
End Sub

Explanation:

This code defines a subroutine named CalculateAverage. 
It declares five variables num1, num2, num3, and average to hold the values of three numbers and their average. 
It sets the values of num1, num2, and num3 to 5, 3, and 7, respectively. 
The average of the three numbers is calculated and displayed in a message box.

The average of three numbers is calculated by adding them together and then dividing the sum by the count of numbers (in this case, 3). 
The MsgBox function displays the result in a message box.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Autofill a series of numbers in a column Qomplainerz 0 390 07-27-2023, 11:23 AM
Last Post: Qomplainerz
  Calculate factorial of a given number in VBA Qomplainerz 0 391 07-27-2023, 11:04 AM
Last Post: Qomplainerz
  Generate random numbers in VBA Qomplainerz 0 417 07-27-2023, 11:03 AM
Last Post: Qomplainerz
  Calculate the avg and color the cells when their values are above or below the avg Qomplainerz 0 430 07-27-2023, 10:41 AM
Last Post: Qomplainerz
  Calculate the sum of values in a column with VBA Qomplainerz 0 360 07-27-2023, 08:18 AM
Last Post: Qomplainerz
  Loop to fill numbers in cells with VBA Qomplainerz 0 380 07-27-2023, 08:16 AM
Last Post: Qomplainerz
  Calculate the factorial of a number with VBA Qomplainerz 0 360 07-27-2023, 07:56 AM
Last Post: Qomplainerz
  Loop to display numbers in VBA Qomplainerz 0 334 07-27-2023, 07:33 AM
Last Post: Qomplainerz
  Floating-point numbers with double precision in VBA Qomplainerz 0 302 07-26-2023, 08:23 PM
Last Post: Qomplainerz
  Floating-point numbers with single precision in VBA Qomplainerz 0 273 07-26-2023, 08:23 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)