VBA(excel) Write an algorithm that solves the problem below. You may use any com
ID: 3667090 • Letter: V
Question
VBA(excel) Write an algorithm that solves the problem below. You may use any combination of pseudo code or VBA syntax discussed in class. Remember to include the purpose, input, output, and body of the algorithm. Create an algorithm for an Excel worksheet that contains a column of numbers starting at cell ”B1”. The algorithm adds the numbers together starting from cell ”B1” and stops when it encounters a cell with a ”SUM” string. When adding numbers, the algorithm skips cells with numbers less than or equal to zero. After, the algorithm replaces the ”SUM” in the worksheet with the sum of numbers.
Explanation / Answer
Algorithm:
Sub calculation()
Dim Sum as Integer
Dim Value as Integer
Dim range as String
Dim i as Integer
i=1
sum=0;
'starting from cell ”B1”
'Assign the value of cell B1 to value
value=Range("B1").value
'stops when it encounters a cell with a ”SUM” string.
while (value<>SUM )
' skips cells with numbers less than or equal to zero.
' It means it adds values greater than zero
if(value>0)
'add the value to sum
sum=sum+value
end if
i=i+1
'move to next cell in the B column
range="B"& i;
'getting value from next cell
value=Range(range).value
end while
'replacing the ”SUM” in the worksheet with the sum of numbers.
Range(range).value=sum
End Sub
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.