【发布时间】:2018-09-25 03:08:24
【问题描述】:
我正在尝试为工作簿每张表中的每个单元格设置公式。我需要在 2 个不同的单元格范围内分配 2 个公式。我在 Variant 中定义了 strFormula 1 和 2。
对于公式1我希望分配到A到AJ列下的单元格
对于公式 2,我希望分配到 AK 到 AR 列下的单元格
我在运行循环后收到以下错误,在定义 strFormulas(2) 时收到语法错误。需要一些帮助来解决这些问题。
谢谢!
运行时错误 1004,应用程序定义或对象定义错误
Dim w As Long
Dim strFormulas(1 To 2) As Variant
For w = 2 To ActiveWorkbook.Worksheets.Count
With ActiveWorkbook.Worksheets(w)
strFormulas(1) = "=IF(ISBLANK('Sheet 1'!A4),"",'Sheet 1'!A4)"
'strFormulas(2) has a syntax error.
strFormulas(2) = "=IF('Sheet 2'!N1838="S","S","")"
.Range("A2:AJ2").Formula = strFormulas(1)
.Range("A2:AJ2000").FillDown
.Range("AK2:AR2").Formula = strFormulas(2)
.Range("AK2:AR2000").FillDown
End With
Next w
【问题讨论】:
标签: vba excel loops for-loop excel-formula