Question

Using a For Next-structure in Excel Write a loop that will calculate the sum of every...

Using a For Next-structure in Excel

Write a loop that will calculate the sum of every third integer, beginning with i = 2 (i.e., calculate the sum 2 + 5 + + 11 + ...) for all values of i that are less than 100. Submit one file with a macro for each loop structure shown below:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

STEP 1 : Open your excel workbook. and press ALT + F11 to open VBE (Visual basic editor)

STEP 2: Right click on your project title from the project explorer. then click on INSERT -> MODULE.

STEP 3: Enter the visual basic code required in the white area on the right pane.

code:

Sub Sum_Every_Third() ' macro function name

Dim LCounter As Integer

  Application.ScreenUpdating = False ' to speedup computing

Application.Calculation = xlCalculationManual    ' to speedup computing

  totsum = 0

For LCounter = 2 To 99 Step 3   ' values from 2 to 99 with stepsize of 3

totsum = totsum + LCounter ' adding very third number

Next LCounter

MsgBox totsum ' to display the result in a message box

Range("A1") = totsum ' to display the result on the cell

  

   Application.ScreenUpdating = True   ' to speedup computing

   Application.Calculation = xlCalculationAutomatic ' to speedup computing

End Sub

press run button (play button) to run the script and verify the result.

STEP 4: Press CTRL + S to save the workbook. Enter workbook name and choose type as 'Excel Macro-Enabled Workbook'.

STEP 5: Press ALT+Q to quit VBE and return to your workbook window. Result will be displayed on cell A1.

If you want to run your custom macro, press ALT+F8 to open macro dialog. Select your macro name and cick on 'Run'. The result will be displayed in cell A1.

ALL THE BEST :D

Add a comment
Know the answer?
Add Answer to:
Using a For Next-structure in Excel Write a loop that will calculate the sum of every...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a for loop that prints the sum of all positive even integers less than...

    1. Write a for loop that prints the sum of all positive even integers less than 200. Assume that variables i and sum are already declared. 2. Write a while loop that prints the sum of all positive odd integers less than 100. Assume that variables i and sum are already declared. 3. Write a do-while loop that prints the sum of all positive multiples of 3 less than or equal to 150. Assume that variables i and sum are...

  • Write a for loop to add all the even numbers to sum, between 0 and 100...

    Write a for loop to add all the even numbers to sum, between 0 and 100 inclusive, that is, like 0 + 2 + 4 + 6 + ….. + 96 + 98 + 100. Use only two integer variables i and sum. Answer in java please

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Solve using Matlab Write a simple loop to list the squares of the first 10 integers....

    Solve using Matlab Write a simple loop to list the squares of the first 10 integers. Using a simple "while" loop, write a script to sum the series 1 + 2 + 3 + ... such that the sum is as large as possible without exceeding 100. The program should display how many terms are used in the sum. Write a script that takes as input an integer n and creates the n*n matrix A with (ij)th component given by...

  • Write a for loop that assigns summed Value with the sum of all odd values from...

    Write a for loop that assigns summed Value with the sum of all odd values from 1 to user Num. Assume userNum is always greater than or equal to 1. Ex: If userNum is 5, then summed Value is 9 (i.e. 1+3+5 =9). Function Save C Reset MATLAB Documentation 1 function summedValue - Oddssum(userNum) summedValue = 0; % Write a for loop that assigns summedValue with the % sum of all odd values from 1 to user Num 7 end...

  • Using the variables shown below and a EOF-controlled loop write a set of C++ statements that...

    Using the variables shown below and a EOF-controlled loop write a set of C++ statements that accumulate the values read from the file in total as long as total does not get greater than max. For example, if the content of the input file is: 10 25 17 6 24 23 12 5 For max = 100, the value in total should be 82 (10+25+17+6+24) For max = 75, the value in total should be 58 (10+25+17+6) Assume that max...

  • Write pseudocode while loop to sum all the values between 2 integers (A & B, input...

    Write pseudocode while loop to sum all the values between 2 integers (A & B, input by the user), including A and B, and print the resulting sum. A must be less than B, otherwise print 0.

  • Statistics Macro Assignment Write a macro to find the number of observations, max, min, sum, aver...

    Statistics Macro Assignment Write a macro to find the number of observations, max, min, sum, average and standard deviation for a column of numbers with any number of observations starting in cell A1 and proceeding downward. The number set will be of any length and include negative, zero, and positive integers. Display the results as shown below. Use the numbers below as an example. You may use the key board code “Selection.End(xlDown).Select” if you wish. Otherwise, use only VBA code...

  • Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values...

    Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values for sin-1(x) from your program to those given by the Excel spreadsheet function ASIN(x). The Maclaurin arcsine expansion is given by x 3x 6 40 (2n)! sin1(x)-2((2n+1) Note: This function by definition is only defined for-1 SxS1. When you write the code for calculating it, you will need to include code that assigns a value to it that reflects it is undefined for values...

  • Write a program that reads two integer values. It then calculates and displays the sum and...

    Write a program that reads two integer values. It then calculates and displays the sum and average of all values between them, Le. if the first value is vi and the second value is 2, then the program calculates and displays the sum and average of all values in the closed range Iv1,2 Your Program must satisfy the following constraints: A. make sure that v1 is less than 2 B. Use a function named getStats(that takes two integer yalues as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT