Question: Microsoft Excel VBA Assignment Using If Statement Assignment The date system that is used by Excel is based on the Gregorian calendar, which is a
Microsoft Excel VBA Assignment
Using If Statement Assignment
The date system that is used by Excel is based on the Gregorian calendar, which is a solar dating system first established in 1582 by Pope Gregory XIII. In the Gregorian calendar, a normal year consists of 365 days. Because the actual time required for the Earth to revolve once about the Sun is actually 365.25635 days, a "leap year" of 366 days is used once every four years to eliminate the error caused by three normal (but short) years. Any year that is evenly divisible by 4 is a leap year: for example, 1988, 1992, and 1996 are leap years.
However, there is still a small error that must be accounted for. To eliminate this error, the Gregorian calendar stipulates that a year that is evenly divisible by 100 (for example, 1900) is a leap year only if it is also evenly divisible by 400. For this reason, the following years are not leap years:
1700, 1800, 1900, 2100, 2200, 2300, 2500, and 2600. This is because they are evenly divisible by 100 but not by 400. The following years are leap years:
1600, 2000, and 2400. This is because they are evenly divisible by both 100 and 400. To determine whether a year is a leap year, follow these steps:
-
If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
-
If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
-
If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
-
The year is a leap year (it has 366 days).
-
The year is not a leap year (it has 365 days).
Your task for this assignment is to create a macro that will do the following:
-
Ask the user, using an InputBox(), to enter a year. Use a meaningful prompt.
-
Determine whether or not the year is a leap year.
-
Use a MsgBox() to display the year and whether or not that year is a leap year. For
example:
-
If the user enters 2019 as the year, your macro displays: 2019 is not a leap year.
-
If the user enters 2016 as the year, your macro displays: 2016 is a leap year.
-
If the user enters 2100 as the year, your macro displays: 2100 is not a leap year.
-
If the user enters 2000 as the year, your macro displays: 2000 is a leap year.
-
IDS 331- Spring 2021 VBA Assignment 8Note: you can use the VBA operator Mod to determine whether or not a number is divisible by
another number.
Pseudocode:
If number1 Mod number2 = 0, then number1 is divisible by number2;
otherwise, number1 is not divisible by number2.
Be sure that you save your Excel file as a macro-enabled workbook.
Submit your Excel file that contains your macro by 10:59 AM on Tuesday, March 16th, 2021.
Note: Late Submissions will be accepted but penalized 4pts up to two days after the deadline. After that, submissions will not be accepted.
Bonus: Assume that the user input should only consist of four digits. Add an if statement to make sure the user entered a number. If yes, check that the user entered a four-digit year value. Otherwise, post and error message and exit the procedure (+5pts).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
