用多个单元格写variables的macros

我试图创build一个甘特图,用有条件的格式更新graphics,但为了做到这一点,我需要编写一个在每个单元格中变化的公式,我已经写了一个macros来做它,它的工作原理,但之后每个单元格都需要被双击才能工作,双击它后自动更新,所以自动计算被启用,如果我使用文本到列,我可以使它们工作,但它们是关于650列和macros自动执行它不工作。

build议将不胜感激。

这是我正在使用的代码:

Sub formula_writer() Row = 2 col = 9 i = 0 row2 = ActiveCell.Row x = 0 While i <= 100 If i >= 99 Then x = x + 1 ActiveSheet.Range("i9").Offset(x, 0).Select i = 0 col = 9 row2 = row2 + 1 End If If x = 20 Then Exit Sub Else aCell = Cells(Row, col).Address(RowAbsolute:=True, ColumnAbsolute:=True) Selection.Formula = "" & "=SI" & "($A$" & row2 & " <> " & Chr(34) & Chr(34) & " , " & aCell & " , " & Chr(34) & Chr(34) & ")" ActiveCell = ActiveCell.Offset(0, 1).Select i = i + 1 col = col + 1 End If Wend i = 0 x = 0 End Sub 

你可以简化你的代码,但主要的问题是代码中的公式(无论R1C1还是A1)应该使用公式名称的英文版本。 试试这个更新:

 Sub formula_writer() Application.ScreenUpdating = False Range("I10:DD28").numberformat="General" Range("I10:DD28").FormulaR1C1 = "=IF(R[10]C1<>"""",R2C,"""")" Application.Calculate Application.ScreenUpdating = True End Sub