Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Range.Offset,但在VBA中弹出“未定义用户定义类型”_Vba_Excel - Fatal编程技术网

使用Range.Offset,但在VBA中弹出“未定义用户定义类型”

使用Range.Offset,但在VBA中弹出“未定义用户定义类型”,vba,excel,Vba,Excel,我在模块中编写了一个简单的函数,如下所示: Function allocate(ByVal pq As PriceQtyClass, ByVal al As AllocationClass) As Boolean Dim tmpRange As Range Dim tmpDic As Dictionary Dim rowIndex As Integer Set tmpDic = pq.priQtyDic Set tmpRange = Applicati

我在模块中编写了一个简单的函数,如下所示:

Function allocate(ByVal pq As PriceQtyClass, ByVal al As AllocationClass) As Boolean

    Dim tmpRange As Range
    Dim tmpDic As Dictionary
    Dim rowIndex As Integer

    Set tmpDic = pq.priQtyDic
    Set tmpRange = Application.ActiveCell.Offset(0, 1)
    rowIndex = 1

    For Each k In tmpDic
        set tmpRange = k 'adding set here isnot working
        rowIndex = rowIndex + 1
    Next

End Function
当它转到tmpRange=k时,用户定义类型未定义的消息弹出

我不知道为什么,哪里错了


请帮忙

在错误行之前添加集合,如集合tmpRange=k。。。希望k是任何类型的范围。@kaz是对的,但priQtyDic是如何定义的?要在字典tmpDic中迭代条目,必须使用tmpDic。键从一个选项显式行开始,并添加一个暗淡的k作为范围声明,这可能会使事情更清楚。@AxelKemper差不多就在这里。在您的Set tmprange=k行中,这需要在@Axel建议的将tmprange=tpmDickI设置为Set tmprange=tpmDickI的更改之后进行更改。恐怕在tmprange之前添加Set不会有帮助。我找到了根本原因,那就是在功能上,我们不能将细胞混合。