gpt4 book ai didi

excel - Excel VBA 中的范围是什么数据类型?

转载 作者:行者123 更新时间:2023-12-02 23:34:07 24 4
gpt4 key购买 nike

我正在尝试使用这样的代码,但失败了:

data = Range("A1")
MsgBox data.Offset(1,1)

这似乎应该打印单元格 B2 的值,但它却给了我一个错误(运行时错误 424:需要对象。)。

那么表达式 Range("A1") 返回什么数据类型,以及如何将 data 声明为正确的数据类型来存储它?

最佳答案

Range 是一个对象。
这意味着您需要使用 set 来分配对象引用:

Dim data As Range
Set data = Range("A1")

Background information :

Set Keyword: In VBA, the Set keyword is necessary to distinguish between assignment of an object and assignment of the default property of the object.

关于excel - Excel VBA 中的范围是什么数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9814238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com