考虑variables范围内的单行?

长时间读者第一次的海报。 当我尝试解释我的困境时,请忍耐,我不是最好的解释者!

所以,我一直在使用各种论坛的各种代码来集成macros,使我的工作更容易,但是我遇到了一些麻烦。 我正在使用以下代码来自动填充并select需要在其他地方复制和粘贴的dynamic范围:

Dim lastRow As Long lastRow = Range("A" & Rows.Count).End(xlUp).Row Range("AP2").AutoFill Destination:=Range("AP2:AP" & lastRow) Range("AQ2").AutoFill Destination:=Range("AQ2:AQ" & lastRow) Range("AR2").AutoFill Destination:=Range("AR2:AR" & lastRow) Range("AS2").AutoFill Destination:=Range("AS2:AS" & lastRow) Range("AT2").AutoFill Destination:=Range("AT2:AT" & lastRow) Range("AU2").AutoFill Destination:=Range("AU2:AU" & lastRow) Range("AP2").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select 

我相信,我面临的问题是最后一行(尽pipe我相信有人会告诉我有一个更简单的方法来处理3-8行)。 在此variables范围返回单个行的实例中, Selection.End(xlDown)第2行中的所有行抓取到底部,这意味着它太大而无法粘贴到目标中。 我怎么能修改这个帐户单行?

FYI Selection.End(xlToRight)总是相同的列数,如果有帮助的话。

提前致谢!

如果您只想从第二行到最后一行select范围AP:AU,只需:

 Range(Range("AP2"), Range("AU" & Cells.Rows.Count).End(xlUp)).Select 

BTW。 我怀疑你想要做的下一件事是Selection.Copy。 不要那样做,只需要replace。select。复制。

 Range(Range("AP2"), Range("AU" & Cells.Rows.Count).End(xlUp)).Copy