Name error from custom VBA function

GrahamCracker19

New Member
Joined
Nov 4, 2015
Messages
13
I have a custom function that has been working with no issues until recently. I made no changes to the code between it working and not working. When I enter the function in a cell excel recognizes it in the formula drop down but when executed it returns the #Name? error.

Any help is greatly appreciated, thank you in advance.

VBA Code:
Function a_FMONTH(ByVal D)
Dim FM As Date

If D >= #1/1/2019# Then FM = #1/15/2019#
If D >= #2/2/2019# Then FM = #2/15/2019#
If D >= #3/2/2019# Then FM = #3/15/2019#
If D >= #3/30/2019# Then FM = #4/15/2019#
If D >= #5/4/2019# Then FM = #5/15/2019#
If D >= #6/1/2019# Then FM = #6/15/2019#
If D >= #6/29/2019# Then FM = #7/15/2019#
If D >= #8/3/2019# Then FM = #8/15/2019#
If D >= #8/31/2019# Then FM = #9/15/2019#
If D >= #9/28/2019# Then FM = #10/15/2019#
If D >= #11/2/2019# Then FM = #11/15/2019#
If D >= #11/30/2019# Then FM = #12/15/2019#

If D >= #1/1/2019# Then FM = #1/15/2019#
If D >= #2/2/2019# Then FM = #2/15/2019#
If D >= #3/2/2019# Then FM = #3/15/2019#
If D >= #3/30/2019# Then FM = #4/15/2019#
If D >= #5/4/2019# Then FM = #5/15/2019#
If D >= #6/1/2019# Then FM = #6/15/2019#
If D >= #6/29/2019# Then FM = #7/15/2019#
If D >= #8/3/2019# Then FM = #8/15/2019#
If D >= #8/31/2019# Then FM = #9/15/2019#
If D >= #9/28/2019# Then FM = #10/15/2019#
If D >= #11/2/2019# Then FM = #11/15/2019#
If D >= #11/30/2019# Then FM = #12/15/2019#


If D >= #1/1/2020# Then FM = #1/15/2020#
If D >= #2/1/2020# Then FM = #2/15/2020#
If D >= #2/29/2020# Then FM = #3/15/2020#
If D >= #3/28/2020# Then FM = #4/15/2020#
If D >= #5/2/2020# Then FM = #5/15/2020#
If D >= #5/30/2020# Then FM = #6/15/2020#
If D >= #6/27/2020# Then FM = #7/15/2020#
If D >= #8/1/2020# Then FM = #8/15/2020#
If D >= #8/29/2020# Then FM = #9/15/2020#
If D >= #9/26/2020# Then FM = #10/15/2020#
If D >= #10/31/2020# Then FM = #11/15/2020#
If D >= #11/28/2020# Then FM = #12/15/2020#

If D >= #1/1/2021# Then FM = #1/15/2021#
If D >= #2/6/2021# Then FM = #2/15/2021#
If D >= #3/6/2021# Then FM = #3/15/2021#
If D >= #4/3/2021# Then FM = #4/15/2021#
If D >= #5/8/2021# Then FM = #5/15/2021#
If D >= #6/5/2021# Then FM = #6/15/2021#
If D >= #7/3/2021# Then FM = #7/15/2021#
If D >= #8/7/2021# Then FM = #8/15/2021#
If D >= #9/4/2021# Then FM = #9/15/2021#
If D >= #10/2/2021# Then FM = #10/15/2021#
If D >= #11/6/2021# Then FM = #11/15/2021#
If D >= #12/4/2021# Then FM = #12/15/2021#

If D >= #1/1/2022# Then FM = #1/15/2022#
If D >= #2/7/2022# Then FM = #2/15/2022#
If D >= #3/7/2022# Then FM = #3/15/2022#
If D >= #4/4/2022# Then FM = #4/15/2022#
If D >= #5/9/2022# Then FM = #5/15/2022#
If D >= #6/6/2022# Then FM = #6/15/2022#
If D >= #7/4/2022# Then FM = #7/15/2022#
If D >= #8/8/2022# Then FM = #8/15/2022#
If D >= #9/5/2022# Then FM = #9/15/2022#
If D >= #10/3/2022# Then FM = #10/15/2022#
If D >= #11/7/2022# Then FM = #11/15/2022#
If D >= #12/5/2022# Then FM = #12/15/2022#

If D > #12/31/2022# Then FM = #9/9/1999#

a_FMONTH = FM

End Function
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It seems to work just fine for me.

Have you placed this code in a General module in VBA, or one of the Sheet modules?

Are you sure that you only have one copy of this code in your workbook?

What is in the cell that you are referencing with the formula?
 
Upvote 0
It seems to work just fine for me.

Have you placed this code in a General module in VBA, or one of the Sheet modules?

Are you sure that you only have one copy of this code in your workbook?

What is in the cell that you are referencing with the formula?
It is placed in a general module. I confirmed that is is the only module in the workbook.
 
Upvote 0
Please answer the last question.

Show us the formula you are using, exactly as you have entered it, and the value of the cell it is referencing.

Also, you may want to confirm that you have VBA enabled for this workbook.
 
Upvote 0
Please answer the last question.

Show us the formula you are using, exactly as you have entered it, and the value of the cell it is referencing.

Also, you may want to confirm that you have VBA enabled for this workbook.
Here is the formula
1650553027654.png


the cell that it is referencing is a date

VBA is enabled for the workbook
1650552870139.png
 
Upvote 0
When I recreate your formula and your table, it works for me.

VBA is enabled for the workbook
Note that is NOT what it says.
It says that by default, VBA is DISABLED, unless it is a digitally singed macro.
Have you digitally signed the macros?

Note that EVERY time you make any sort of change to the macros, the current signature is discarded, and you will need to re-sign the macros again.
 
Upvote 0
Solution
When I recreate your formula and your table, it works for me.


Note that is NOT what it says.
It says that by default, VBA is DISABLED, unless it is a digitally singed macro.
Have you digitally signed the macros?

Note that EVERY time you make any sort of change to the macros, the current signature is discarded, and you will need to re-sign the macros again.
That did the trick! Thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top