从不同的范围读取到数组并覆盖 VBA 中的相同范围
Reading from Distinct Ranges into Array and Overwriting to Same Ranges in VBA
我想从不同的范围读取,其中有通过这些单元格中的某些公式计算的值,在 VBA 中并用已保存的值覆盖这些范围,以便自动删除单元格中的公式。
代码如下所示:
allValues = Range("AR8:AW8,AR10:AW10,AR12:AW24,AR26:AW52,AR54:AW61,AR64:AW87,AR89:AW94,AR96:AW96,AR98:AW104,AR106:AW106,AR108:AW110,AR112:AW122,AR125:AW140,AR142:AW162,AR164:AW192,AR194:AW196,AR198:AW198,AR200:AW202,AR204:AW218,AR220:AW230,AR232:AW232,AR234:AW240").Value
Range("AR8:AW8,AR10:AW10,AR12:AW24,AR26:AW52,AR54:AW61,AR64:AW87,AR89:AW94,AR96:AW96,AR98:AW104,AR106:AW106,AR108:AW110,AR112:AW122,AR125:AW140,AR142:AW162,AR164:AW192,AR194:AW196,AR198:AW198,AR200:AW202,AR204:AW218,AR220:AW230,AR232:AW232,AR234:AW240")= allValues
对于合取范围,这样的想法可行,但对于这些则完全没有。
感谢任何意见。
使用 multi-area 范围,迭代区域:
Dim r As Range
For Each r In Sheet1.Range("AR8:AW8, AR10:AW10, ..., ...").Areas
r.Value = r.Value
Next
我会像下面这样:
With Range("AR8:AW8,AR10:AW10,AR12:AW24,AR26:AW52,AR54:AW61,AR64:AW87,AR89:AW94,AR96:AW96,AR98:AW104,AR106:AW106,AR108:AW110,AR112:AW122,AR125:AW140,AR142:AW162,AR164:AW192,AR194:AW196,AR198:AW198,AR200:AW202,AR204:AW218,AR220:AW230,AR232:AW232,AR234:AW240")
.Value = .Value
End With
我想从不同的范围读取,其中有通过这些单元格中的某些公式计算的值,在 VBA 中并用已保存的值覆盖这些范围,以便自动删除单元格中的公式。
代码如下所示:
allValues = Range("AR8:AW8,AR10:AW10,AR12:AW24,AR26:AW52,AR54:AW61,AR64:AW87,AR89:AW94,AR96:AW96,AR98:AW104,AR106:AW106,AR108:AW110,AR112:AW122,AR125:AW140,AR142:AW162,AR164:AW192,AR194:AW196,AR198:AW198,AR200:AW202,AR204:AW218,AR220:AW230,AR232:AW232,AR234:AW240").Value
Range("AR8:AW8,AR10:AW10,AR12:AW24,AR26:AW52,AR54:AW61,AR64:AW87,AR89:AW94,AR96:AW96,AR98:AW104,AR106:AW106,AR108:AW110,AR112:AW122,AR125:AW140,AR142:AW162,AR164:AW192,AR194:AW196,AR198:AW198,AR200:AW202,AR204:AW218,AR220:AW230,AR232:AW232,AR234:AW240")= allValues
对于合取范围,这样的想法可行,但对于这些则完全没有。
感谢任何意见。
使用 multi-area 范围,迭代区域:
Dim r As Range
For Each r In Sheet1.Range("AR8:AW8, AR10:AW10, ..., ...").Areas
r.Value = r.Value
Next
我会像下面这样:
With Range("AR8:AW8,AR10:AW10,AR12:AW24,AR26:AW52,AR54:AW61,AR64:AW87,AR89:AW94,AR96:AW96,AR98:AW104,AR106:AW106,AR108:AW110,AR112:AW122,AR125:AW140,AR142:AW162,AR164:AW192,AR194:AW196,AR198:AW198,AR200:AW202,AR204:AW218,AR220:AW230,AR232:AW232,AR234:AW240")
.Value = .Value
End With