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

后端 未结 2 1619
抹茶落季
抹茶落季 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:25

    I've just encountered this Q&A having the same problem. I think there is a kind of bug for using CurrentRegion within UDF and the reason is not as Peter suggest in his answer.

    Compare these two function:

    Function GetAddressOfColumn(TopCell As Range)
        GetAddressOfColumn = TopCell.CurrentRegion.Address
    End Function
    
    
    Function GetAddressOfColumnOK(TopCell As Range)
        GetAddressOfColumnOK = Range(TopCell, TopCell.End(xlDown)).Address
    End Function
    

    Both function use different kind of range references. If Peter were right both should return false result. So, look at the data range below and the result of both function. As you can see second function result is as expected and correct.

    enter image description here

提交回复
热议问题