excel - 为什么将我的数组读入 VBA 中的单元格时,它会重复每一行?
问题描述
我的代码简单地写着:
Board = Array(1,2,3,4,5,6,7,8,9)
Range("A1:C3") = Board
但是当执行时,在 A1 到 C1、A2 到 C2 和 A3 到 C3 行中重复 1、2、3。我该如何解决?
解决方案
使用二维数组:
Dim Board(1 To 3, 1 To 3) As Variant 'or As Long
Dim i As Long, j As Long
For i = LBound(Board, 1) To UBound(Board, 1)
For j = LBound(Board, 2) To UBound(Board, 2)
Dim counter As Long
counter = counter + 1
Board(i, j) = counter
Next
Next
Range("A1:C3").Value = Board
推荐阅读
- svg - 内联 svg vs svg Sprite vs 多个外部文件
- progressive-web-apps - 有没有办法在测试运行设置中将 PWA 添加到主屏幕并在测试运行拆解中将其从主屏幕中删除
- apache-spark - Spark没有从二进制文件中读取所有记录
- javascript - 带有网络和 Sceenchooser 的 React-Native Router Flux
- javascript - 如何在 html 网站上使用 javascript 读取和写入另一个文件?
- swift - 从 ViewRouter 和 ObservableObjects 或 environmentObject 指向 SwiftUI 中的所有三个视图
- react-native - 在 React Navigation 5 中设置组件属性值
- r - 检测 R 中日常数据的季节性
- python-3.x - 如何根据熊猫中列的条件进行聚合?
- django - 如果提供了额外的字段,Django 使表单测试无效