我正在尝试使用WITH块插入一些值和公式。简单的公式的分配很好,但是当它到达第一个多个公式(.Range(“ J2”)中的一个)时,它将引发1004应用程序定义的错误或对象定义的错误。我假设我的地方出了问题语法,但我看不到。我确定我还记得几年前的一些事情,那就是必须使用&符号在代码中拆分公式,但是不确定。请提前感谢。
在此问题上,我已经查看了所有其他解决方案以及其他一些站点,但是似乎没有一个解决方案足以回答我的问题。
With MainPg
lstrw = .Cells(.Rows.Count, "A").End(xlUp).Row
'.Range("A1") = "article"
.Range("B1") = "season"
.Range("C1") = "bu name"
.Range("D1") = "dept"
.Range("E1") = "range name"
.Range("F1") = "item name"
.Range("G1") = "stroke"
.Range("H1") = "colour"
.Range("I1") = "stroke name"
.Range("J1") = "newness"
.Range("K1") = "equivalent stroke/colour"
.Range("L1") = "pre-lockdown category"
.Range("M1") = "post-lockdown category"
.Range("B2").Formula = "='Upload'!A2"
.Range("C2").Formula = "='Upload'!F2"
.Range("D2").Formula = "='Upload'!G2"
.Range("E2").Formula = "='Upload'!K2"
.Range("F2").Formula = "='Upload'!L2"
.Range("G2").Formula = "='Upload'!H2"
.Range("H2").Formula = "='Upload'!J2"
.Range("I2").Formula = "='Upload'!M2"
.Range("J2").Formula = "=IF(INDEX('Upload'!C:C," & "MATCH([@article],'Upload'!E:E,0))=43597,""Y"",""N"")"
.Range("L2").Formula = "=IF(LEN([@[Equivalent Stroke/Colour]])<1,INDEX('Upload'!O:O,MATCH([@article],'Upload'!E:E,0)),INDEX('LastYear'!J:J,MATCH([@[Equivalent Stroke/Colour]],'LastYear'!I:I,0)))"
.Range("M2").Formula = "=IF([@[pre lockdown category]]=""UNCATEGORISED"",""REGULAR"",[@[pre lockdown category]])"
.Range("B2:M2").Copy
.Range("B3:M" & lstrw).PasteSpecial.xlPasteFormulas
Set rng1 = Range("A1:M" & lstrw)
Set table1 = .ListObjects.Add(xlSrcRange, rng1, , xlYes)
table1.TableStyle = "TableStylemedium13"
End With