WISE OWL EXERCISES
EXCEL VBA MACROS EXERCISES
Excel VBA Macros | Messages and variables exercise | Enter Dating Agency Details into Input Boxes
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
You can learn how to do this exercise if you attend the course listed below!
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Open the WODA Application.xlsm file. Your task is to create subroutines which can be attached to the two buttons on the application form.
The text on the buttons should provide a clue as to what they should do.
Create a subroutine which you can attach to the Add Details button. A basic outline for this procedure could be:
- Declare variables to hold each value the user will enter.
- Use input boxes to ask the user to enter each value and capture the result in the variables you have declared.
- Write the value of each variable into the appropriate cell on the worksheet.
- Present a message which informs the user that the application is complete.
For reference, the code to capture the value of an input box is:
MyVariable = InputBox("Type something")
Right-click on the Add Details button and choose to assign the procedure you have written.
Click the button to check that the system works.
Type a value into each input box and click OK to see the next one.
At the end of the procedure, all of the cells should be filled in.
You can display a message to tell the user that the application is complete.
Now create a subroutine which you can attach to the Edit Details button.
This will be identical to the first subroutine except that you'll use the value of each cell to set the Default parameter of each input box.
Attach the subroutine to the Edit Details button. Click the button to test that the system works.
Each input box should appear with the current value already displayed.
Save and close the file.
What is the purpose of using variables at all here? Why not simply do something like:
Range("C4").Value = InputBox(Range("B4").Value)
I think the main answer to that is that this is an exercise designed to teach how to use variables! But even were this not the case, it's often better to store intermediate values in variables, if nothing else because it makes it easier to debug code (you can inspect the value of variables to see if they're correctly set). That said, if you're comfortable not using variables for this example, don't!