简体   繁体   English

在 Excel VBA 中使用 UDF 名称中的数字

[英]use of numbers within name of UDF in Excel VBA

I added the following functions:我添加了以下功能:

Function map() As Integer
   map = 1
End Function
Function map_2() As Integer
   map_2 = 1
End Function
Function map2() As Integer
   map2 = 1
End Function

The first two functions work.前两个函数起作用。 But the last one - doesn't - I am getting #REF error.但最后一个 - 没有 - 我收到#REF错误。 Why is it?为什么?

It looks like excel treats them as cell address.看起来 excel 将它们视为单元格地址。

I tried map22() , mpa22() , map333() - they don't work.我尝试map22()mpa22()map333() - 它们不起作用。 But map_22() , map_333() work.但是map_22()map_333()有效。 I am using Excel 2013我正在使用 Excel 2013

The Reason is because Excel treats 1, 2 or 3 letters followed by any number of letters as a cell reference:原因是因为 Excel 将 1、2 或 3 个字母后跟任意数量的字母视为单元格引用:

  • =A1
    Reference to Cell A1引用单元格 A1
  • =BB22
    Reference to Cell BB22引用单元格 BB22
  • =MAP2
    Reference to nonexistent Cell MAP2引用不存在的 Cell MAP2
    As in: Column "MAP", Row "2"如:“MAP”列,“2”行

If we make the same general arrangement with "Real" cells, we get the same ref.如果我们对“真实”单元格进行相同的总体安排,我们会得到相同的参考。

在此处输入图像描述
在此处输入图像描述

I would encourage to you use your =MAP_1 as I don't really know any way around it.我鼓励你使用你的=MAP_1因为我真的不知道有什么办法可以解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM