[英]How to copy and paste a range of cells from another worksheet depending on predefined indices in VBA
I'm struggling to see why one can't do the following with respect to a block of a worksheet cell. 我正在努力查看为什么不能对工作表单元格的块执行以下操作。 (It works when I do a similar thing for other instances).
(当我对其他实例执行类似操作时,它会起作用)。 Ultimately I'm trying to paste a formula (that calls a different sheet), across a range in my "Input" sheet.
最终,我试图在“输入”表中的某个范围内粘贴一个公式(调用另一个表)。
The formula should read... 该公式应显示为...
=+D14*(1+Sheet1!$D$4)
For the first cell, and it should change automatically for all other cells in the range. 对于第一个单元格,该范围内的所有其他单元格应自动更改。
Here is a simplified version of my code to get an idea as to what I've tried so far... Thanks: 这是我的代码的简化版本,以了解到目前为止我已经尝试过的内容...谢谢:
Option Explicit
Sub PasteTest()
Dim ws(1) As Object
Set ws(1) = Worksheets("Input")
Dim idx_1, idx_2, idx_3 As Long 'no of cells
idx_1 = 76
idx_2 = 8
idx_3 = 3 + idx_2 + idx_1
ws(1).Range("D" & idx_3 & ":DR" & idx_2).Formula "=D14*(1+Sheet1!" & Chr(36) & "D" & Chr(36) & "4)"
End Sub
Dim ws As Object
Set ws = Worksheets("Input")
And then: 接着:
Dim idx_1 As Long, idx_2 As Long, idx_3 As Long
And at the end: 最后:
ws.Range("D" & idx_3 & ":DR" & idx_2).Formula = "=D14*(1+Sheet1!" & Chr(36) & "D" & Chr(36) & "4)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.