在Excel VBA中可以用cells(1,1).resize(10,20)读取数据吗?

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:27:55
例如:
dim a$(1 to 10,1 to 20)

为什么下面的用法可以:
cells(1,1).resize(10,20)=a

而下面的用法却出错呢:
a=cells(1,1).resize(10,20)?
我的目的是想一次性把一定范围(如:A1:T10)内的数据快速读取到一个数组中,然后进一步处理。

视乎楼主的目的, 及要什麼效果
如 a = 101
Cells(1,1).resize(10,20) = a
A1:T10 的所有单元格 都变成 101

如 a=Cells(1,1).resize(10,20), 当然是错, 情况如在单元格打上 =A1:T10 都是出错误值

Cells(1,1).resize(10,20)是A1:T10的地址
如欲 a 设为 A1:T10 的地址, 要加 Set
Set a = Cells(1,1).resize(10,20)

如欲 a 是 A1:T10 的和
a = application.sum(Cells(1,1).resize(10,20))
------------------------------------------
应用 Set a = Cells(1,1).resize(10,20)
无前无后, 我较难判决
最重要是楼主是否明白Set的作用

可以。给10行20列的单元格区域,可以考虑使用数组。

视乎楼主的目的, 及要什麼效果
如 a = 101
Cells(1,1).resize(10,20) = a
A1:T10 的所有单元格 都变成 101

如 a=Cells(1,1).resize(10,20), 当然是错, 情况如在单元格打上 =A1:T10 都是出错误值

Cells(1,1).resize(10,20)是A1:T10的地址
如欲 a 设为 A1:T10 的地址, 要加 Set
Set a = Cells(1,1).resize(10,20)

如欲 a 是 A1:T10 的和
a = application.sum(Cells(1,1).resize(10,20))
------------------------------------------
应用 Set a = Cells(1,1).resize(10,20)
无前无后, 我较难判决