【发布时间】:2015-06-25 10:58:10
【问题描述】:
我有一个名为“SicknessRecordGraded”的电子表格,其中包含不同数量的行。
列 A - F (1 - 6),有原始内容要计算。
然后从 I - AG (9 - 33) 列中,有一系列公式可以计算 A - F 中的信息。
我正在准备一个 vba 宏来自动将公式范围从 I - AG 复制到 A - F 中有内容的每一行中。
我一直在尝试如下编写宏。我有使用 .resize 函数正确复制的范围,但是我还没有弄清楚如何粘贴到正确的范围内。
Public Sub experiment2()
Dim rw As Long
rw = 3
' Select initial sheet to copy from
Sheets("SicknessRecordGraded").Select
' Find the last row of data - xlUp will check from the bottom of the spreadsheet up.
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
' For loop through each row
For x = 1 To FinalRow
Cells(rw, 9).Resize(1, 33).Copy ' Resize from intial range. Columns I - AG.
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 'Continue incrementing through the rows.
Cells(NextRow, 1).Select ' Find the next row.
ActiveSheet.Cells(NextRow, "I").PasteSpecial xlPasteAll ' Paste information.
Sheets("SicknessRecordGraded").Select 'Reselect sheet to copy from. Probably uneccessary.
Next x
End Sub
我认为要修改的行是
ActiveSheet.Cells(NextRow, 1).PasteSpecial xlPasteAll ' Paste information.
包含另一个范围函数。
【问题讨论】:
-
您是否知道
Cells(x, 9).Resize(9, 33)调整为 9 行 x 33 列的范围,而不是从第 9 列到第 33 列的单行范围? -
看起来不是这样。这很有用。