Excel VBA function works in Visual Basic, but fails in Worksheet

后端 未结 2 1617
抹茶落季
抹茶落季 2020-12-04 00:43

I\'m trying to build a 2D array of data using \"CurrentRegion\".

Function ProcessData()
Dim dataList()
dataList = Range(\"A1\").CurrentRegion
\' TODO Process         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-04 01:28

    If you call a Function from an Excel cell (i.e. as an User-Defined-Function/UDF), you can only access the ranges that are handed to the function via parameters. Any access to other ranges (and .CurrentRegion is a range) will result in a "Circular Reference" potential cancellation of the execution.

    Also, in a UDF you cannot modify anything on the worksheet - but only return the result of function!

    For further details, check out this link.

提交回复
热议问题