Question

In: Computer Science

(EXCEL) On a new sheet called Hello, insert numbers into the range A1: E10. The following...

(EXCEL) On a new sheet called Hello, insert numbers into the range A1: E10. The following code is used to format some data. This code works perfectly well, but it is quite repetitive. Rewrite it by using as many with constructions as make sense. Using appropriate indentation and then run your modified code to make sure it still works.

Sub FormatARange()

ActiveWorkbook.Worksheets("Hello").Range("B1").Font.Bold = True ActiveWorkbook.Worksheets("Hello").Range("B1").Font.Size = 14 ActiveWorkbook.Worksheets("Hello").Range("B1").Interior.Color = vbYellow ActiveWorkbook.Worksheets("Hello").Range("B1").HorizontalAlignment = xlLeft ActiveWorkbook.Worksheets("Hello").Range("A3:A8").Font.Bold = True ActiveWorkbook.Worksheets("Hello").Range("A3:A8").Font.Italic = True ActiveWorkbook.Worksheets("Hello").Range("A3:A8").Interior.Color = vbGreen ActiveWorkbook.Worksheets("Hello").Range("A3:A8").InsertIndent 1 ActiveWorkbook.Worksheets("Hello").Range("B2:E2").Font.Bold = True ActiveWorkbook.Worksheets("Hello").Range("B2:E2").Font.Italic = True ActiveWorkbook.Worksheets("Hello").Range("B2:E2").Font.Color = vbYellow ActiveWorkbook.Worksheets("Hello").Range("B2:E2").Interior.Color = vbBlue ActiveWorkbook.Worksheets("Hello").Range("B2:E2").HorizontalAlignment = xlRight ActiveWorkbook.Worksheets("Hello").Range("B3:E8").Interior.Color = vbRed ActiveWorkbook.Worksheets("Hello").Range("B3:E8").NumberFormat = "$#,##0"

End Sub

Solutions

Expert Solution

VBA code:

Sub FormatARange()
Dim sheet As Worksheet
Set sheet = Sheets("Hello")
With sheet.Range("B1")
.Font.Bold = True
.Font.Size = 14
.Interior.Color = vbYellow
.HorizontalAlignment = xlLeft
End With
With sheet.Range("A3:A8")
.Font.Bold = True
.Font.Italic = True
.Interior.Color = vbGreen
.InsertIndent 1
End With
With sheet.Range("B2:E2")
.Font.Bold = True
.Font.Italic = True
.Font.Color = vbYellow
.Interior.Color = vbBlue
.HorizontalAlignment = xlRight
End With
With sheet.Range("B3:E8")
.Interior.Color = vbRed
.NumberFormat = "$#,##0"
End With
End Sub

Sample output:

Explanation:

Set sheet = Sheets("Hello")

assiging worksheet Hello to variable sheet. Hereafter we can refer worksheet hello by variable name sheet. so we don't want to repeatedly use ActiveWorkbook.Worksheets("Hello").

With Statement

The key feature of the with the statement is that we can access the properties of the object without referring to the object multiple times. The method to access the properties of the object lies in the dot keyword. When we put a dot keyword we can see a multiple number of options to access the properties of the object.


Related Solutions

Microsoft Excel Insert a 2D Line chart on the sheet from the range D23:F23 for the...
Microsoft Excel Insert a 2D Line chart on the sheet from the range D23:F23 for the three years in the range D4:F4. Question: how do you select the two different ranges and insert a line chart
what is the formula in excel to get probability answers on range of numbers - Question:...
what is the formula in excel to get probability answers on range of numbers - Question: mean number is 10.3 per day standard deviation is 2.25 per day for any day what is the probability that the number of customers returning items is between 12 and 14 I don't know how to write the equation to obtain P
What order would I need to insert the numbers 1 to 7 into a new AVL...
What order would I need to insert the numbers 1 to 7 into a new AVL tree in order to ensure that there was no need to perform a rotation.
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence,...
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, … etc. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. We define Fib(0)=0,...
Copy and paste, or type, the following into cells A1:D5 of an Excel spreadsheet: Input data...
Copy and paste, or type, the following into cells A1:D5 of an Excel spreadsheet: Input data fixed cost 16,000 Units 1,050 variable cost per unit 4.75 revenue =D2*B4 sell price per unit 6.5 expenses =B2+(B3*D2) profit =D3-D4 Use Excel's Goal Seek to answer the following question. Assuming that demand is fixed at 1,050 units, what is the sell price per unit that results in break even? Enter only the numerical solution. Do
2. Write the hexadecimal numbers in the registers of $a0, $a1, $a2, $a3 after the following...
2. Write the hexadecimal numbers in the registers of $a0, $a1, $a2, $a3 after the following codes running: ori $a0, $0, 11 ori $a1, $0, 19 addi $a1, $a1, -7 slt $t2, $a1, $a0 beq $t2, $0, label addi $a2, $a1, 0 sub $a3, $a1,$a0 j end_1 label: ori $a2, $a0, 0 add $a3, $a1, $a0 end_1: xor $t2, $a1, $a0 *Values in $a0, $a1, $a2, $a3 after the above instructions are executed.
PLEASE COMPUTE THE FOLLOWING IN EXCEL and show the excel sheet, Thank you so much! The...
PLEASE COMPUTE THE FOLLOWING IN EXCEL and show the excel sheet, Thank you so much! The following are the runs scored totals for 9 players for the 2016 New York Yankees: 56,43,63,68,58,80,71,32,19 (a) Find the mean and median (b) Find the standard deviation of this population (c) Considering this as a normal sample of American League players for the 2016 season, find a 99% Confidence Interval for the actual mean of Runs Scored for AL players, 2016 . (d) Considering...
Solve the following question by using python language In range of 1-10000 if the numbers are...
Solve the following question by using python language In range of 1-10000 if the numbers are divisible by n1 increase count by 1 , if the number is divisible by n2 increase count by 2, and if the number are divisible by n3 increase the count by 3 if none of the above conditions match for the number, increase count by the number. n1=10 +17 n2=50 +21 n3=100 +9
Write a Java program to generate random numbers in the following range a. 1 <=n <=...
Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 JAVA PROGRAMMING
1. Using the Data Set, create and calculate the following in Excel®: Determine the range of...
1. Using the Data Set, create and calculate the following in Excel®: Determine the range of values in which you would expect to find the average weekly sales for the entire sales force in your company 90% of the time, and calculate the following: A. The impact of increasing the confidence level to 95% B. The impact of increasing the sample size to 150, assuming the same mean and standard deviation, but allowing the confidence level to remain at 90%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT