问题
I hope someone will be able to help with a problem that has surfaced with a recent Excel update.
If I define two range names in an Excel worksheet and then enter =Index(PeriodList,MonthNo) in cell A13 via the UI, I find that Thisworkbook.Names.Count in VBA reports 2 - as expected. However, if I execute Activesheet.Range("A13").Formula = "=Index(PeriodList,MonthNo)" in VBA, Thisworkbook.Names.Count reports 3 and I find that a new name that cannot be deleted is created. The name is _xlfn.SINGLE. The existence of this name is a problem for a significant number of widely distributed Excel templates that fail when attempting to delete this name. This only became a problem after a recent Excel update.
The problem seems to be with the MonthNo element in that "=Index(PeriodList,1)" does not generate the _xlfn.SINGLE name.
Can anyone identify how to enter something that is the equivalent of "=Index(PeriodList,MonthNo)" in VBA without creating the unwelcome _xlfn.SINGLE name?
回答1:
If the function has worked for you in the past and has only recently become an issue, you should check with your IT department as it points to a problem with the version of Excel being used.
_xlfn.SINGLE is displayed for dynamic array functions when they are not supported by the version of Excel that is running.
https://support.office.com/en-us/article/issue-an-xlfn-prefix-is-displayed-in-front-of-a-formula-882f1ef7-68fb-4fcd-8d54-9fbb77fd5025
There are many dynamic array VBA solutions available such as here. https://bettersolutions.com/vba/arrays/dynamic-size.htm
Use this code to display all defined names in the UI Names Manager. Then you can delete the named ranges of your choice, including those that were previously hidden.
Sub ShowAllDefinedNames()
'Source: https://professor-excel.com/named-ranges-excel-hidden-names/
Dim tempName As Variant
'Unhide all names in the currently open Excel file
For Each tempName In ActiveWorkbook.Names
tempName.Visible = True
Next
End Sub
回答2:
After much further investigation I came upon the note at https://support.office.com/en-gb/article/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd which indicates that the formula now needs to be array entered with CTRL+SHIFT+ENTER. Now the _xlfn.SINGLE name is no longer created. Problem solved.
来源:https://stackoverflow.com/questions/59121799/indexperiodlist-monthno-creating-xlfn-single-name-in-workbook