简体   繁体   English

VBA - 复制单元格并粘贴列中的空白行

[英]VBA - Copy Cell and Paste Down Blank Rows in Column

I am making a template for others to paste their data into the file, and for a macro to run and copy formulas down all rows that contain data.我正在制作一个模板,供其他人将他们的数据粘贴到文件中,并制作一个宏来运行和复制包含数据的所有行的公式。 The sheet contains headers.该工作表包含标题。 The formula is in column D (Price).公式在 D 列(价格)中。 I want the macro to start in cell D2, and copy the formula in cell D2 down all rows in column D.我希望宏在单元格 D2 中开始,并将单元格 D2 中的公式复制到 D 列中的所有行。

示例文件

Through trial and error, and mashing up different recommendations, this is what works for my purposes:通过反复试验,并混合不同的建议,这对我的目的有用:

Public Sub CopyDownRows()公共子 CopyDownRows()

Dim rng As Range Dim LR As Long Dim rng As Range Dim LR As Long

Sheets("Sheet1").Select
LR = Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("D3:D" & LR)
Range("D").Select
Selection.Copy
rng.Select
ActiveSheet.Paste

End Sub结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM