Professional Documents
Culture Documents
Calculate Sum
Sub CalculateSum()
On Error GoTo 0
Next cell
Else
End If
End Sub
2. Positive or negative
Sub CheckNumber()
Else
End If
End Sub
3. Grade check
Sub CheckGrade()
score = Range("A1").Value
' Determine the grade based on the score
Case Is >= 90
grade = "A"
Case Is >= 80
grade = "B"
Case Is >= 70
grade = "C"
Case Is >= 60
grade = "D"
Case Else
grade = "F"
End Select
End Sub
Sub CalculateSum()
Sub CalculateSum()
total = 0
For counter = 1 To 10
Next counter
End Sub
Sub CalculateFactorialWhileLoop()
factorial = 1
Do While number > 0
number = number - 1
Loop
End Sub
Sub FindPowerOf2UntilLoop()
powerOf2 = 1
exponent = 0
exponent = exponent + 1
powerOf2 = 2 ^ exponent
Loop
MsgBox "The smallest power of 2 greater than 1000 is 2^" & exponent & " = " &
powerOf2
End Sub
8. Calculate Rectangle Area
Sub CalculateRectangleArea()
End Sub
Sub CreateTableExample()
newWorksheet.Name = "DataSheet"
newWorksheet.Cells(2, 2).Value = 30
newWorksheet.Cells(3, 2).Value = 25
End Sub
Sub ColorCellsExample()
' Loop through each cell in the range and change the background color
Next cell
End Sub
MyFunction = x ^ 3 - 2 * x - 5
End Function
Sub BisectionMethod()
a=1
b=2
tolerance = 0.0001
midPoint = (a + b) / 2
If MyFunction(midPoint) = 0 Then
Exit Do
ElseIf MyFunction(a) * MyFunction(midPoint) < 0 Then
b = midPoint
Else
a = midPoint
End If
Loop
End Sub
Sub CalculateSumAndAverageUsingArrays()
Set dataRange = Range("A1:A10") ' Set the range containing the data
totalSum = 0
Dim i As Long
Next i
Dim average As Double
MsgBox "Total Sum: " & totalSum & vbNewLine & "Average: " & average
End Sub