我想将范围内的所有内容乘以一个值。我尝试了这种格式,但值变得太离谱了。
代码:
Dim yl1 As Range
Set yl1 = .Range(.Cells(17, 6), .Cells(n + 16, 6))*19.25
根据链接:
Dim yl1 as Range
Set yl1 = .Range(.Cells(17, 6), .Cells(n + 16, 6))
yl1.Value = .Evaluate("INDEX(" & yl1.Address(0,0) & " * 19.25,)")
它会一次完成所有任务。
可能还有其他方法,其中许多可能更好,但其中一种只是循环
For i = 17 to some last row
Cells(i, 6) = Cells(i, 6) * 19.25
Next i
不过,我觉得这种方式最直观。
另一种方式:
Sub UsingPaste()
Range("B1").Value = 0.7
Range("B1").Copy
n = 10
Range(Cells(17, 6), Cells(n + 16, 6)).PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
End Sub
其中B1是一些未使用的单元格,而n则是它碰巧是什么。