简体   繁体   English

Excel-将公式复制到X列中的一个字段中,并向下复制到VBA中的最后一行

[英]Excel - copy formula in one field across X columns and down to the last row in VBA

Let's say I had this formula in cell B2 假设我在单元格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))),"")

In VBA< how would I copy this down to the last row and across to (and including column P) 在VBA <中,我如何将其复制到最后一行并跨到(包括P列)

I've seen examples where it shows a single column but not multiple eg VBA to fill formula down till last row in column 我看过一些示例,其中只显示一列,而不显示多个列,例如VBA,用于将公式填充到该列的最后一行

Assuming the number of rows is determined by data in column A, then try: 假设行数由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

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

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