Question

In: Computer Science

For VBA: Complete this problem on Sheet1. The user will select a cell on Sheet1 and...

For VBA:

Complete this problem on Sheet1.

The user will select a cell on Sheet1 and input a positive number (you do not know which cell will be selected ahead of time). This cell automatically becomes the active cell. Next, create a macro named problem1 that will perform the following tasks:

• Obtain the value in the active cell and store it in a variable.

• In the cell to the right of the original active cell, output 5 plus the value in the original active cell

• In the cell above the original active cell, output one-half the value in the original active cell

• In the cell below the original active cell, output the square root of the value in the original active cell

Create a run button on Sheet1 that executes problem1.

Your macro must work for any positive number input into any cell. For example, if you type 36 in cell B3 and then click the run button, the number 41 will appear in C3, the number 18 will appear in B2, and the number 6 will appear in B4. Then if you click on cell D5, type 25, and click the run button, the number 30 will appear in E5, the number 12.5 will appear in D4, and the number 5 will appear in D6.

You can assume the user will not input the value in the first or last row, nor the last column (Think about what will happen if the value is input into one of those cells. Or better yet, try doing it and see what happens.).

Assume the user will input a value in the active cell before clicking the run button.

Use the Option Explicit statement for this macro and in all future macros that you create. This will force you to declare your variables.

Hint: When the run button is clicked, whatever cell is selected at that time automatically becomes the active cell. You can move to the right, above, and below the active cell by using relative references in your program. This will require you to use ActiveCell.Offset() three times.

PLEASE take screenshots of VBA code and excel. Thank you

Solutions

Expert Solution

The VBA Code (in text) is:

Option Explicit
'Option Explicit would mean all variables need to be declared as Dim

Sub Add() 'Make the sub routine and name it
Dim x As Integer 'Declare the variable
x = ActiveCell.Value 'Store the Value of the Active Cell in the variable
ActiveCell.Offset(0, 1).Value = x + 5 'Offset the Active Cell by 1 column to the right and store x+5 in it
ActiveCell.Offset(-1, 0).Value = x / 2 'Offset the Active Cell by 1 row above and store x/2 in it
ActiveCell.Offset(1, 0).Value = x ^ 0.5 'Offset the Active Cell by 1 row below and store square root of x in it
End Sub 'End the sub routine

The VBA Code (screenshot) is:

To make a macro:

Step 1.

Step 2:

Step 3. Assign Macro to a Button:

The file is now ready. Enter a number in a cell and click on the box/button while the cell is selected.

The Output looks like this:

An up-vote/thumbs-up would be greatly appreciated!


Related Solutions

Program on Visual Basic, VBA Create an application that lets the user enter a number of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Time Calculator ( PROGRAM VBA EXCEL) Create a application that lets the user enter a number...
Time Calculator ( PROGRAM VBA EXCEL) Create a application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than...
(EXCEL vba) Problem: Trying to remove the entire row if the year is before 2019. Current...
(EXCEL vba) Problem: Trying to remove the entire row if the year is before 2019. Current code: Range("B2").Select Do Until ActiveCell.Value = "" If ActiveCell.Value < 2019 Then ActiveCell.EntireRow.Delete Else ActiveCell.Offset(1, 0).Select End If Loop Code Problem: My data sets can be 1000's of rows so checking every cell is very slow. Since the data is always in order, all I need to do is find the first entry <2019 and then select xlDown and delete everything, but I don't...
Select one problem that relates to you and your current position in the work environment. Complete...
Select one problem that relates to you and your current position in the work environment. Complete your response in 750-1,000 words. Support your response with personal experiences or examples. Alternate Scenario: If you are in an industry that does not deal with any foreign exchange transactions, use the petroleum industry for this assignment. Imagine that you work for a domestic oil refinery, and answer either question G11-1 or G11-2. You do not work for an oil producer, but rather for...
The cathode in a voltaic cell and in an electrolytic cell is Select one: a. the...
The cathode in a voltaic cell and in an electrolytic cell is Select one: a. the site of oxidation and of reduction, respectively. b. the site of reduction and of oxidation, respectively. c. positive in both cells. d. the site of reduction in both cells. e. the site of oxidation in both cells.
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
TO BE DONE IN JAvA Complete the calculator program so that it prompts the user to...
TO BE DONE IN JAvA Complete the calculator program so that it prompts the user to enter two integers and an operation and then outputs the answer. Prompt the user three times, don't expect all the inputs on one line. Possible operations are + - * / No other words or symbols should be output, just the answer. Requested files import java.util.Scanner; /** * This is a simple calculator Java program. * It can be used to calculate some simple...
Create a class (Shapes) that prompts the user to select a shape to be drawn on...
Create a class (Shapes) that prompts the user to select a shape to be drawn on the screen. Objects: Circle, X, box, box with an x inside, or any other object of your choice. Depending on the user’s choice, you will then ask for the number of rows, columns or any requirements needed to draw the shape. Finally, you will display the shape selected by the user to the screen. Your class should have at least one instance variable. Your...
Complete the following table by writing the name of the cell structure or organelle in the...
Complete the following table by writing the name of the cell structure or organelle in the right hand column that matches the structure/function in the left hand column. Structure/Function Cell structure 1. May store water, needed chemicals and wastes in plant cells 2. The “sugar factory” in plant cells that contains chlorophyll 3. Small structure that makes protein 4. Long whip-like structures used for movement 5. The region of the cell between the plasma membrane and the nucleus 6. Cell...
You are interested in the complete oxidation of glucose in a cell. If the pyruvate dehydrogenase...
You are interested in the complete oxidation of glucose in a cell. If the pyruvate dehydrogenase complex was inhibited, what product would you expect would be the first to accumulate in the cell?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT