Question
Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it to a size equal to an assigned value of
Microsoft Excel VBA (Visual Basic for Applications) Programming Language
Objectives: Create an array and redim it to a size equal to an assigned value of a variable, populate the array with a series of random numbers, output the array to a message box and to a worksheet.
Instructions:
- Review the variables already declared. You won't need others.
- See comments in the code that will act as your guide. Add new code directly after each comment.
- Assign a value of intRandom. (start with 20, change it later, if desired)
- ReDim the array to be of a size equal to the previous variable.
- Fill the array with random numbers using RND function.
- Loop through the array and create a message string.
- Also, create a title that pulls the value of the sixth elements.
- Display the title and message in a Msgbox.
- Output the array to the output sheet with index value in column A and the random number in column B.
Lines of code needed: about 16 including 3 for each of 3 loops
The message box should like like the following:
________________________________________________________
Option Explicit
Option Base 1
' ******** DSS 620 TEMPLATE ---- Created by John A. Michl jmichl@sju.edu ********
' **
' ** Module 4 Exercise 2
' ** Template Revision: 01/12/2018 v1.1 by John A. Michl
' ** Note: Professor's comments preceeded by '[
' ** Instructions / hints preceeded by '>>
' ** Student comments should use apostrophe only
' **
' ** Assignment modified by STUDENT NAME on DATE
' **
' ******************************************************************************
Sub RandomList()
' all variables needed for Part A have been declared
Dim i As Integer ' number of random numbers to make
Dim intRandom As Integer ' number of random numbers to make
Dim arrRandom() As Single ' array in which to store numbers
Dim strMsg As String
Dim strTitle As String
Randomize ' this initializes the random number generator
Debug.Print Rnd ' just to show how easy it is to create a
Worksheets("Output").Range("A:B").Clear ' remove old results
']vvvvv Student code below vvvvvv
'] assign a value to intRandom
'] redim the array to be the appropriate size
'] fill the array with random numbers using a loop
'] create the list of numbers for the message string using a loop
'] be sure to include both the index value i and the contents of the array
'] create the message title to show the random number in position 6 of the array
'] see the screen shot but note the random numbers will be different
'] display the message box
'] output the array to the output worksheet showing the index number in
'] column A and the random number in column B
'^^^^ Student code above
End Sub
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started