简体   繁体   中英

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. Why is it?

It looks like excel treats them as cell address.

I tried map22() , mpa22() , map333() - they don't work. But map_22() , map_333() work. I am using Excel 2013

The Reason is because Excel treats 1, 2 or 3 letters followed by any number of letters as a cell reference:

  • =A1
    Reference to Cell A1
  • =BB22
    Reference to Cell BB22
  • =MAP2
    Reference to nonexistent Cell MAP2
    As in: Column "MAP", Row "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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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