29040_VBA Basic Concepts Practice Exercises 2003

3
Practice Exercises 1. Create a routine in the VBA window to create a new sheet(and name the activesheet ‘Practice Sheet’) after the last sheet and copy the data from a9:h9 to the same range in the new sheet. Then autofit columns A:H of the Practice sheet. 2. Write a routine that produces an input box asking for your age. Then using the value you entered into the input box work out how many years until retirement (using 65 as retirement age). Then enter the text “You will retire in “ followed by the result of the calculation and then the word “ Years” in cell A4 of the new sheet you created. So the result for me would be: a. E.g. You will retire in 27 years. 3. Create a routine that places the numbers 1 to 10 across cells a2 to J2. Use a loop.

description

29040_VBA Basic Concepts Practice Exercises 2003

Transcript of 29040_VBA Basic Concepts Practice Exercises 2003

Practice Exercises

1. Create a routine in the VBA window to create a new sheet(and name the activesheet Practice Sheet) after the last sheet and copy the data from a9:h9 to the same range in the new sheet. Then autofit columns A:H of the Practice sheet.2. Write a routine that produces an input box asking for your age. Then using the value you entered into the input box work out how many years until retirement (using 65 as retirement age). Then enter the text You will retire in followed by the result of the calculation and then the word Years in cell A4 of the new sheet you created. So the result for me would be:

a. E.g. You will retire in 27 years.

3. Create a routine that places the numbers 1 to 10 across cells a2 to J2. Use a loop.4. Write a formatting procedure that does the following:

a. Using the range a9:h9 on the Practice sheet.i. Make them bold.ii. Make them italics.iii. Change the font colour using your choice of RGB values. (Continued in next page).iv. Change the font to Garamond and font size to 16.v. Autofit the columns.

b. Merge and Centre cell A4 of the practice sheet.

c. Using the range a2:j2 centre align and bold the numbers.

Write one or more simple macros to fill in capital cities on different worksheets (shows selecting worksheets and selecting cells)

Write macros to select various ranges absolutely using a battleships game as template

Select one cell in a battleships grid relative to another

Write a simple macro to guide Red Riding Hood through a maze, using lots of OFFSET commands

Write a macro to select the last task in a block of tasks

Write a macro to select a column of data, then amend it to select a rectangular block (both using the END keyword)

Create a macro to select almost down to the bottom of a block of Muppets data (using OFFSET and END)

Practise on a battleships grid using more difficult selection techniques, such as resizing a selection and using the UNION method