我正在尝试将公式粘贴到一系列单元格中(我只希望将其粘贴到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
答案 0 :(得分:1)
请注意
.Cells(.Rows.count, 1).End(xlUp).Row
为您提供第1列最后使用的行,即A列。
您可以使用...
.Cells(.Rows.count, "K").End(xlUp).Row
相反,获取列K中最后使用的行。
另外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