0

我只是想将一个 WB 的内容复制到另一个

strColNos = Range(Cells(65536, rngSMonthYr.Column).Address(False, False)).End(xlUp).Row
For intLastCell = 2 To strColNos
    strCell1 = Cells(intLastCell, rngSMonthYr.Column).Address(False, False)
    strCell2 = Cells(intLastCell, rngDMonthYr.Column).Address(False, False)

    Workbooks(wkbSource).Sheets(wsSource).Range(strCell1).Copy _
        Destination:=Workbooks(wkbDestination).Sheets(wsDestination).Range(strCell2)
Next intLastCell

strCell1 的值为“D2”(源书),strCell2 的值为“F2”(目标书)

rngSMonthYr、rngDMonthYr 基本上是输入框,用户可以在其中从源表和目标表中选择特定月份。我需要将所有行从选定的源列复制到选定的目标列。

任何帮助将不胜感激。

谢谢,亚伦

4

1 回答 1

0

无需遍历每个单元格。此外,您可以寻址范围而无需一直将它们转换为地址字符串。这段代码应该做你需要的:

intLastRow = Cells(65536, rngSMonthYr.Column).End(xlUp).Row
Sheet1.Cells(2, rngSMonthYr.Column).Resize(intLastRow - 1).Copy _
    Sheet2.Cells(2, rngDMonthYr.Column).Resize(intLastRow - 1)

我不确定,如果你需要使用rngSMonthYr.Column- 或者是否rngSMonthYr足够。如果单元格包含列号,.Column则错误,必须省略。

于 2013-10-02T08:06:15.960 回答