Question
write the program in VBA
b. Write a program that uses a For loop to perform the following steps: a. Prompt the user to input two integers: firstNum an
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have answered the question below.

Code:

Sub program()
Dim firstNum, secondNum, i, n As Integer
firstNum = InputBox("Enter firstNum: ")
secondNum = InputBox("Enter secondNum: ")
If firstNum < secondNum Then
n = secondNum - firstNum - 1
Dim odd_sum, even_sum As Integer
odd_sum = 0
even_sum = 0
For i = firstNum + 1 To secondNum - 1
If i Mod 2 = 0 Then
msg1 = msg1 & i & vbTab
even_sum = even_sum + i
Else
msg2 = msg2 & i & vbTab
odd_sum = odd_sum + i
End If
Next i
MsgBox "Even Numbers between " & firstNum & " and " & secondNum & ":" & vbTab & msg1 & vbNewLine
MsgBox "Sum of Even numbers: " & even_sum & vbNewLine
MsgBox "Odd Numbers between " & firstNum & " and " & secondNum & ":" & vbTab & msg2
MsgBox "Sum of Odd numbers: " & odd_sum & vbNewLine
Else
MsgBox "firstNum should be less than secondNum"
End If
End Sub

Snapshot of the code with explanation in comments:

Sub program () Dim firstNum, secondNum, i As Integer Declare firstNum, secondNum as integers firstNum = InputBox(Enter first

Sample Output:

Microsoft Excel Х Enter firstNum: OK Cancel 1  Microsoft Excel х Enter secondNum: OK Cancel 15

Microsoft Excel Х 2 4 6 8 Even Numbers between 1 and 15: 10 12 14 OKX Microsoft Excel Sum of Even numbers: 56 OK

Microsoft Excel x 3 5 7 9 Odd Numbers between 1 and 15: 11 13 OKMicrosoft Excel X Sum of Odd numbers: 48 OK

If you have any doubts feel free to ask me in comments,

Thank you, Have a nice day..!!

Add a comment
Know the answer?
Add Answer to:
write the program in VBA b. Write a program that uses a For loop to perform...
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
  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • Write a complete Java program that uses a for loop to compute the sum of the...

    Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25.

  • Write a C++ program that asks the user to enter a single number from 1 to...

    Write a C++ program that asks the user to enter a single number from 1 to 50 and a choice of "even" or "odd". Using a recursive function, output the sum of all the even or odd integers from 1 up to (and including) that number. Your program does not need to loop and accept more input (only one input of the number then even/odd).

  • Write a Python named numbersread.py that uses a loop to read and process numbers.txt. The program...

    Write a Python named numbersread.py that uses a loop to read and process numbers.txt. The program should output all of the integers, one per line, and then output the total of the even integers and the total of the odd integers.

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • Write a VBA Sub Program to perform matrices multiplication of matrix A and B using 2D...

    Write a VBA Sub Program to perform matrices multiplication of matrix A and B using 2D arrays. a. Get the number of rows and columns of both matrix A and B from the user, and check if multiplication is possible with matrix A and B. b. If matrices multiplication is possible, input the matrix A and B using arrays and multiply matrix A and B.

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Write a program that will loop ten times. In each iteration prompt user to enter an...

    Write a program that will loop ten times. In each iteration prompt user to enter an integer between -50&50. Print the input, keep a running sum of the inputs, and track the minimun and maximum numbers input. After the loop is complete, minimum number entered, maximum number entered, sum of all numberes entered, and average of all numbers entered. Format all output. Before running the loop, print the label "Input values: ". Within the loop, print value entered by user...

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
ADVERTISEMENT