Excel - 在X列中的一个字段中复制公式,然后在VBA中复制到最后一行

时间:2017-08-15 10:21:21

标签: excel vba excel-vba excel-formula

假设我在B2单元格中有这个公式

=IFERROR(MID($A2,FIND("|",SUBSTITUTE($A2,"@","|",B$1)),IFERROR(FIND(" ",$A2,FIND("|",SUBSTITUTE($A2,"@","|",B$1))),LEN($A2)+1)-FIND("|",SUBSTITUTE($A2,"@","|",B$1))),"")

在VBA<我如何将其复制到最后一行并跨越(包括P列)

我见过一些例子,它显示的是一列但不是多列,例如VBA to fill formula down till last row in column

1 个答案:

答案 0 :(得分:1)

假设行数由A列中的数据确定,则尝试:

Dim lRow As Long
With ActiveSheet
    lRow = .Cells(Rows.Count, 1).End(xlUp).Row
    .Range("B2:P" & lRow).FormulaR1C1 = "=IFERROR(MID(RC1,FIND(""|"",SUBSTITUTE(RC1,""@"",""|"",R1C)),IFERROR(FIND("" "",RC1,FIND(""|"",SUBSTITUTE(RC1,""@"",""|"",R1C))),LEN(RC1)+1)-FIND(""|"",SUBSTITUTE(RC1,""@"",""|"",R1C))),"""")"
End With