[英]Paste a formula into a range of cells using macros
I'm trying to paste a formula into a range of cells (I only want it to paste until the last used row of column K), but I keep getting a syntax error我正在尝试将公式粘贴到一系列单元格中(我只希望它粘贴到 K 列的最后使用行),但我不断收到语法错误
With ThisWorkbook
With .Sheets("Ex")
lRow4 = .Cells(.Rows.count, 1).End(xlUp).Row
Set rng4 = .Range("J6:J" & lRow4)
rng4. FormulaR1C1."=IF(RC[1]='Lease & RPM Charges'!R[-4]C[-6],UPPER(TEXT(REPLACE(REPLACE('Lease & RPM Charges'!R[-4]C[-7],5,0,""-""),8,0,""-""),""DD-mmm-YY"")))"
End With
End With
End Sub
Note that注意
.Cells(.Rows.count, 1).End(xlUp).Row
gives you the last used row of column 1 which is column A.为您提供第 1 列的最后使用的行,即 A 列。
You can use …您可以使用 …
.Cells(.Rows.count, "K").End(xlUp).Row
instead, to get the last used row in column K.相反,获取列 K 中最后使用的行。
Also rng4. FormulaR1C1.
还有
rng4. FormulaR1C1.
rng4. FormulaR1C1.
should be rng4.FormulaR1C1 =
应该是
rng4.FormulaR1C1 =
With ThisWorkbook.Sheets("Ex")
lRow4 = .Cells(.Rows.count, "K").End(xlUp).Row
Set rng4 = .Range("J6:J" & lRow4)
rng4.FormulaR1C1 = "=IF(RC[1]='Lease & RPM Charges'!R[-4]C[-6],UPPER(TEXT(REPLACE(REPLACE('Lease & RPM Charges'!R[-4]C[-7],5,0,""-""),8,0,""-""),""DD-mmm-YY"")))"
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.