Microsoft Developer
Looping over collections exercise
Average difficulty

This Microsoft Developer LOOPING OVER COLLECTIONS exercise is provided to allow potential course delegates to assess their suitability for the Wise Owl EXCEL 2007 VISUAL BASIC course only, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Exercise: Elmer - colouring cells

A full answer to this exercise is provided as part of the training course!

1) Download the files needed to start this exercise: exercise-917.zip (and click here if you experience any problems unzipping this file after downloading it).
2) When you open the file above, you should see Elmer the elephant.  It's worth noting that this picture has nothing whatsoever to do with this exercise!
Exercise screen-shot 2067 Elmer is a playful but responsible elephant - here seen with his duck
3) Create a macro to colour (say) A1:J10 at the top left of the worksheet in random colours from 1 to 32.
Training exercise hint Use a line which sets the Interior.ColorIndex property of each cell in the range to Int(math.rnd()*32)- and ask your trainer to explain this if it doesn't make sense!
4) Here is what the worksheet should look like after you run your macro:
Exercise screen-shot 2068 This is the effect you should get
5) If you get the macro working, try nesting it inside another loop so that the pattern is continually redrawn.  Here is the outline of the code to do this:
Exercise screen-shot 2069 100 times is more than enough to get the idea!
6) Save this workbook as Elmer pattern.xlsm, before you do serious damage to your eyes!

Thank you for showing an interest in this Excel 2007 Visual Basic training course! As mentioned above, full answers to this and other exercises are provided on the course. On all Wise Owl scheduled courses delegates can take away these model answers (together with their own efforts!) on a free USB stick.

All content copyright Wise Owl Business Solutions Ltd 2008.  All rights reserved..