寻找一种简单,优雅的解决方案,将其当前形式的范围附加到另一个工作表的最后一行下。
范围:
Columns
对类似问题的几个回答似乎过于复杂,与Columns(number) & last row
用法不兼容-是的,我是VBA的新手。例如,拒绝插入表达式question.py:1:0: W0401: Wildcard import tkinter (wildcard-import)
question.py:5:27: E1101: Instance of 'Starting' has no 'frame' member (no-member)
question.py:8:31: E1101: Instance of 'Starting' has no 'frame' member (no-member)
question.py:12:31: E1101: Instance of 'Starting' has no 'frame' member (no-member)
question.py:4:23: W0613: Unused argument 'master' (unused-argument)
question.py:16:11: C0121: Comparison to None should be 'expr is None' (singleton-comparison)
question.py:17:30: E1101: Instance of 'Starting' has no 'frame' member (no-member)
question.py:24:8: E1101: Instance of 'Starting' has no 'frame' member (no-member)
question.py:25:8: E0602: Undefined variable 'Question1' (undefined-variable)
语法。
非常感谢。
答案 0 :(得分:0)
请尝试下一个代码。不必复制整个列。该代码计算工作表的最后填充行以复制该列,并计算目标工作表列的第一个空行:
Sub AppendToOtherSheet()
Dim shC As Worksheet, wsR As Worksheet, lastRowC As Long, lastRowR As Long
Set shC = Sheets("conf_9")
Set wsR = Sheets("Rec_9")
lastRowC = shC.Range("E" & Rows.Count).End(xlUp).row
lastRowR = wsR.Range("I" & Rows.Count).End(xlUp).row + 1
shC.Range("E2:E" & lastRowC).Copy Destination:=wsR.Cells(lastRowR, 9)
shC.Range("F2:F" & lastRowC).Copy Destination:=wsR.Cells(lastRowR, 10)
shC.Range("G2:G" & lastRowC).Copy Destination:=wsR.Cells(lastRowR, 7)
shC.Range("H2:H" & lastRowC).Copy Destination:=wsR.Cells(lastRowR, 8)
shC.Range("L2:L" & lastRowC).Copy Destination:=wsR.Cells(lastRowR, 6)
End Sub
上面的代码假定所有列的行数均相同,并且要复制列的工作表具有列标题。
如果讨论中的列没有相同的行数,则必须为要复制的每一列计算lastRowC
和lastRowR
。如果没有列标题,则要复制的范围(例如)将从第一条复制代码行中的“ E1”而不是“ E2”开始。