How to Fix the Excel DatePart #NAME? Error Using the YEAR Function
Question details
The user needs an alternative to the DatePart function to extract the year or generate successive dates in Excel worksheets without causing an error.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Extracting the year from a specific date or generating subsequent monthly dates within an Excel spreadsheet.
- Observed behavior
- Excel displays a #NAME? error because the DatePart function, which is specific to Access and VBA, is not recognized as a standard Excel worksheet formula.
Ensure that your target cells contain valid date values rather than plain text, as Excel requires standard date formats to perform formula-based date calculations.
Use the YEAR Function to Extract the Year
Since DatePart is unsupported in worksheets, use Excel's native YEAR function to easily pull the four-digit year from any date cell.
Excel stores dates as sequential serial numbers (e.g., 45078) to perform calculations. The DatePart function triggers a #NAME? error because it only works in VBA code or Access databases. The standard worksheet equivalent is the YEAR function.
Click on the empty cell where you want the extracted year to be displayed.
Type the formula =YEAR(A1) into the formula bar, replacing 'A1' with the cell reference that contains your date.
Press Enter. The cell will now display the four-digit year corresponding to the date.

Use the EDATE Function for Monthly Increments
If your goal with DatePart was to add or subtract months to generate a timeline, the EDATE function is the correct worksheet alternative.
Fix Date Formula Errors Easily with WPS Spreadsheet
WPS Spreadsheet provides robust, built-in date and time functions, including YEAR and EDATE, allowing you to manipulate date serial numbers smoothly without needing VBA. It fully recognizes standard formulas to prevent annoying #NAME? errors.
- 1. Open your spreadsheet: Launch WPS Spreadsheet and open the document containing your date data.
- 2. Select a calculation cell: Click on the cell where you want to output the year or the subsequent month.
- 3. Input native functions: Type =YEAR(A1) to extract the year or =EDATE(A1, 1) for monthly date additions.
- 4. Press Enter: Hit Enter on your keyboard to instantly calculate the correct date value without encountering the #NAME? error.

Frequently Asked Questions
Why does the DatePart function work in Access but not in Excel?
DatePart is exclusively a VBA (Visual Basic for Applications) and Microsoft Access function. When you type it directly into an Excel worksheet cell, the software does not recognize the function name in its standard formula library, resulting in a #NAME? error.
How does Excel store dates internally?
Excel stores dates as sequential serial numbers so they can be easily manipulated in mathematical calculations. By default, January 1, 1900, represents serial number 1, and each subsequent day increases the serial number by one.
Can I extract the month and day without the DatePart function?
Yes. Just like the YEAR function, Excel provides built-in MONTH() and DAY() functions. You can use =MONTH(A1) to return the month as a number from 1 to 12, or =DAY(A1) to get the numerical day of the month from 1 to 31.
What are other common causes of the #NAME? error in Excel?
The #NAME? error usually indicates a typo in the formula name, forgetting to place double quotation marks around text strings, or referencing a named range that does not exist. Double-checking formula syntax is the best way to resolve it.




