Question

VBA LOOPS The two macros in this homework should be assigned to separate buttons and should...

VBA LOOPS

The two macros in this homework should be assigned to separate buttons and should be located on the same worksheet.

When you are done, upload your saved workbook below.

Be sure to write your code in a module in the workbook you will submit, not in your personal workbooks or sheets. To access the correct module, go to your “Visual Basic,” right-click “Microsoft Excel Objects” in the workbook you are submitting, and then click “Insert” and “Module.”

Problem 1: Write a Sub that prints out numbers 1 through 25 in an Excel worksheet using any type of Loop (e.g., Do Until, Do While, For).

Problem 2: Create a nested-loop program (you can use any type of loop you would like).

This nested loop should take the names input (below) and print out every possible combination of first and middle names. These input names will need to appear in your workbook somewhere. Then, output every possible combination of first and middle names somewhere in the worksheet. Your program should work correctly with more or less first names and middle names. Below is an example of input and output. To save space, only the names associated with the first two first names are shown in the example output.

Input

First names Middle names
Penelope Jill
Gwyneth Diane
Alice Heidi
Anna Lilly
Victoria

Example Output

First names Middle names
Penelope Jill
Penelope Diane
Penelope Heidi
Penelope Lilly
Penelope Victoria
Gwyneth Jill
Gwyneth Diane
Gwyneth Heidi
Gwyneth Lilly
Gwyneth Victoria
etc. etc.

Homework Answers

Answer #1

Problem 1:

Sub Button1_Click()
' Generating numbers from 1 to 25
' Using For loop
For i = 1 To 25
' Writing data to Cell
Cells(i, 1).Value = i
Next i
End Sub

Sample Run:

_________________________________________________________________________________________

Problem 2:

Sub Button2_Click()
' Prints the combination of First and Last names
  
' Declaring Variables
Dim first, last As String
Dim k As Integer
k = 3
  
' Looping over first names
For i = 3 To 6
'Fetching first name
first = Cells(i, 7).Value
' Looping over Last names
For j = 3 To 7
'Fetching last name
last = Cells(j, 8).Value
'Printing into another cells
Cells(k, 10).Value = first
Cells(k, 11).Value = last
k = k + 1
Next j
Next i
End Sub

Sample Run:

Know the answer?
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
Similar Questions
In this assignment you will analyze the performance of actual company divisions. FASB ASC 280 (formerly...
In this assignment you will analyze the performance of actual company divisions. FASB ASC 280 (formerly SFAS 131) requires publicly traded companies to disclose segment information in the notes to the financial statements. You will use Excel to create visually appealing data tables and bar charts to analyze division performance, and then comment on the results.    Due Date: Tuesday, May 1, 2018.   Submit as an attachment in Blackboard in the Module 24 Assignment. SECTION I The link is to...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT