我第一次在这里发帖。我正在尝试将具有 10 个元素的阵列复制到 10 个单独的范围。问题是所有单元格都只有阵列中的第一个元素。在下面的例子中,我只得到 ON。我不会在第 3 到第 5 个范围内关闭。 编辑我试图在不使用回圈的情况下执行此操作,因为我可能有很多元素并且在复制程序中速度变慢。
Dim Rng As String
Dim OnOff() As Variant
Rng = "F7,G4,H3,I9,J8,K2,L10,M1,N6,O5"
OnOff = Array("ON", "ON", "OFF", "OFF", "OFF", "ON", "ON", "ON", "ON", "ON")
Range(Rng).Value = OnOff
这就是我得到的:
这是我希望得到的:
uj5u.com热心网友回复:
写入非连续范围
- 尝试创建两个单独的单元格地址字符串。
Const rgOnAddress As String = "F7,G4,L10,M1,N6,O5"
Const rgOffAddress As String = "H3,I9,J8"
Range(rgOnAddress).Value = "ON"
Range(rgOffAddress).Value = "OFF"
uj5u.com热心网友回复:
根据您发布的图片你只是想通过回圈Rng
和OnOff
simultanoeusly
Dim Rng As String
Dim OnOff() As Variant
Rng = "F7,G4,H3,I9,J8,K2,L10,M1,N6,O5"
OnOff = Array("ON", "ON", "OFF", "OFF", "OFF", "ON", "ON", "ON", "ON", "ON")
Dim i As Long
Dim v As Variant
v = Split(Rng, ",")
For i = LBound(OnOff) To UBound(OnOff)
Range(v(i)) = OnOff(i)
Next i
由于似乎需要写入非连续范围,因此可以使用此链接中的代码来加快速度。
0 评论