如果单元格等于产品和date,则在交叉单元​​格VBA中input公式

BCD 1/1 1/2 1/3 2 Product 1 ? 3 Product 2 

我正在尝试使用VBA来自动插入基于产品名称和date标准的公式。 尝试了多种方式,包括索引匹配,相交,但似乎无法得到它的工作!

目前我的公式是根据另一个工作表的date手动放置的。 公式供参考

 =IFERROR(IF(VLOOKUP($B$1&$C39&Japan!$E39,TDM!$A:$AA,23,0)=Japan!U$33,SUMIF(Allocation!$A:$A,Japan!$A39,Allocation!$S:$S),"")*$G39,"") 

有没有办法使用VBA自动化?

尝试这个 :

 Sub Fill_Formula() Dim StartRow As Long StartRow = 2 For i = StartRow To 50 'Start and End Rows For j = 2 To 10 'Start and End Columns Cells(i, j).Formula = _ "IFERROR(IF(VLOOKUP($B$1&$C" & 39 + (i - StartRow) & "&Japan!$E" & 39 + (i - StartRow) & ",TDM!$A:$AA,23,0)=Japan!U$" & 33 + (i - StartRow) & ",SUMIF(Allocation!$A:$A,Japan!$A" & 39 + (i - StartRow) & ",Allocation!$S:$S),"")*$G" & 39 + (i - StartRow) & ","")" Next j Next i End Sub