我正在尝试浏览工作表中的一系列单元格并在每个单元格中编写一个公式。
但我不断收到错误:
Run-time error '1004'
Application-defined or object-defined error
代码现在看起来像这样:
Sub updateFormulasForNamedRange()
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
Dim row, col, fieldCount As Integer
colCount = 13
RowCount = 60
For col = 1 To colCount
For row = 1 To RowCount
Dim strColCharacter
If col > 26 Then
strColCharacter = Chr(Int((row - 1) / 26) + 64) & Chr(((row - 1) Mod 26) + 65)
Else
strColCharacter = Chr(row + 64)
End If
Worksheets("Rawdata1").Cells(row, col).FormulaR1C1 = "=IF(Numbers1!$E$" & col & "<>0;Numbers1!" & "$" & strColCharacter & "$" & row & ";"""")"
Next row
Next col
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
End Sub
它在将公式分配给单元格的行处失败。我尝试用“test”替换该字符串,并且它有效。但正是这个字符串不被接受。即使它与当前所在单元格的公式栏中的字符串完全相同。
那根绳子对我来说看起来不错吗?
"=IF(Numbers1!$E$1<>0;Numbers1!$A$1;"")"
我不太清楚所有 Formula 属性的区别,但我尝试了它们的变体,并且都抛出相同的错误。那么什么可能导致这个错误呢?
您的问题出在 .FormulaR1C1 上。这告诉公式需要行号、列号样式的公式引用,但随后您为其提供地址(列、行)样式的公式。
将 .FormulaR1C1 更改为 .Formula
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)