简体   繁体   English

如何根据VBA中的预定义索引从另一个工作表复制和粘贴一系列单元格

[英]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.

相关问题 使用 VBA 将一系列单元格从一个工作表复制到另一个工作表 - Copy a range of cells from one worksheet to another using VBA 将粘贴范围从一个工作表复制到另一个 - Copy paste range from one worksheet to another 将单元格粘贴到VBA中的另一个工作表 - Paste cells to another worksheet in VBA Excel VBA如何将WorkSheet名称与单元格值匹配,然后复制并粘贴一系列单元格 - Excel VBA How to match WorkSheet name with Cell value, then Copy and Paste a Range of Cells VBA代码可将特定单元格中的特定单词复制并粘贴到另一个工作表中 - VBA code to copy and paste specifc words in different cells to another worksheet VBA:如何通过工作表模块中的“填充”或“复制/粘贴”(或任何多个单元格)找到正在编辑的范围 - VBA: How to locate range being edited through “fill down” or “copy/paste” (or any multiple cells) in worksheet module Excel VBA复制/粘贴范围从1个工作表到另一个,每次相同的范围粘贴到下一个目标列 - Excel VBA copy/paste range from 1 worksheet to another, same range pastes in next destination column each time 如何让 VBA 复制一系列单元格,等待单元格计算并粘贴到另一个范围? - How do I get VBA to Copy a range of cells, WAIT FOR THE CELLS TO CALCULATE and paste in another range? Excel VBA复制/粘贴范围到另一个工作表中的下一个可用单元格 - Excel VBA Copy/Paste Range to the next available cell in another worksheet 如何根据标题复制一系列单元格以粘贴到另一个工作表并匹配标题? - How can I copy a range of cells based on a Header to paste to another worksheet and match the headers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM