Consulting

Results 1 to 3 of 3

Thread: Help with a while wend loop

  1. #1
    VBAX Newbie
    Joined
    Sep 2007
    Posts
    1
    Location

    Question Help with a while wend loop

    Does anyone know how to complete the following in the VBA editor. I am having alot of trouble with this and help would be greatly appreciated.




    1. Prompt the user to enter the number of random numbers between 20 and 100 to be generated.

    2. Use a While/Wend loop to generate the random numbers, and write them to A1:A100.

    3. Calculate average of the random numbers; write a label in C1 and the average in D1; also the average should be rounded to a whole number.

    4. Create a private function called Compare that has two arguments: The random number and the average. The function will return an integer. The function will test three conditions:
    1. Number is greater than average, return a 1.
    2. Number is equal to average, return a 2.
    3. Number is less than the average, return a 3.

    5. Since each number must be passed to Compare, a While/Wend loop should be constructed first.

    6. With in the body of the loop, an If/Then/ElseIf statement will be required to invoke the function; pass random number and pass average; determine if a 1, 2, or 3 was returned from Compare function.

    7. If the result is a 1, a label stating the number is greater than the average should be written to the sheet. If the result is 2, a label stating the number is equal to the average should be written to the sheet. If the result is 3, a label stating the number is less than the average should be written to the sheet.

    8. Create a Clear Module that will clear the spreadsheet.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    If this is not homework, I don't know what is.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by ccknight
    .1 Prompt the user to enter the number of random numbers between 20 and 100 to be generated
    Look at Input box in Help.

    Quote Originally Posted by ccknight
    2 Use a While/Wend loop to generate the random numbers, and write them to A1:A100
    Look at While and Rnd in help.

    Quote Originally Posted by ccknight
    3 Calculate average of the random numbers; write a label in C1 and the average in D1; also the average should be rounded to a whole number
    Work out how you would do it on paper, and code that.

    Quote Originally Posted by ccknight
    4 Create a private function called Compare that has two arguments: The random number and the average. The function will return an integer. The function will test three conditions:.
    .1. Number is greater than average, return a 1..
    .2. Number is equal to average, return a 2..
    .3. Number is less than the average, return a 3
    Work out how you would do it on paper, and code that.

    Quote Originally Posted by ccknight
    5 Since each number must be passed to Compare, a While/Wend loop should be constructed first
    Use info from 2.

    Quote Originally Posted by ccknight
    6 With in the body of the loop, an If/Then/ElseIf statement will be required to invoke the function; pass random number and pass average; determine if a 1, 2, or 3 was returned from Compare function
    Look at If in Help.

    Quote Originally Posted by ccknight
    7 If the result is a 1, a label stating the number is greater than the average should be written to the sheet. If the result is 2, a label stating the number is equal to the average should be written to the sheet. If the result is 3, a label stating the number is less than the average should be written to the sheet
    Look at Range in Help, especially the Value property.

    Quote Originally Posted by ccknight
    8 Create a Clear Module that will clear the spreadsheet..
    Do it in Excel using the macro recorder.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •