无法获取范围类的formularArray属性

时间:2018-02-27 13:57:57

标签: excel-vba vba excel

以下是我的代码,我收到此错误:

  

无法设置范围类

的formulararray属性
Sub Auto_TTAnalysis_RANREPORT()
'
' Auto_TTAnalysis_RANREPORT Macro
'

'
    Columns("B:B").Select
    Selection.Copy
    Columns("M:M").Select
    Selection.Insert Shift:=xlToRight
    Columns("K:K").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("N:N").Select
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    Selection.Copy
    Columns("O:O").Select
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    Selection.Copy
    Columns("P:P").Select
    Selection.Insert Shift:=xlToRight
    Range("M1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "BTS"
    Range("N1").Select
    ActiveCell.FormulaR1C1 = "Category"
    Range("O1").Select
    ActiveCell.FormulaR1C1 = "Outage in ins"
    Range("P1").Select
    ActiveCell.FormulaR1C1 = "15 mins"
    Range("N2").Select
    Selection.FormulaArray = _
        "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100),""No Site Outage"",IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100),""No Cell Outage"",IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5,""Worst Cell"",""Site Outage"")))"
    Range("N2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("O2").Select
    Application.CutCopyMode = False
    Selection.FormulaArray = "=(100-AVERAGEIFS(C[-3],C[-13],RC[-2]))*24*60/100"
    Range("O2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("P2").Select
    Application.CutCopyMode = False
    Selection.FormulaArray = _
        "=IF(RC[-1]>15,""More than 15 mins"",""Within 15  mins"")"
    Range("P2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Application.CutCopyMode = False
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$P$8275").AutoFilter Field:=12, Criteria1:="0.00"
    Range("A5").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete
    Range("K1").Select
    Selection.AutoFilter
    Range("A1").Select
    Sheets("HUAWEI").Select
    Selection.CurrentRegion.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Font
        .Size = 9
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .TintAndShade = 0
    End With
    With Selection
        .HorizontalAlignment = xlGeneral
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("A1").Select
    Selection.AutoFilter
    Columns("I:J").Select
    Selection.Delete Shift:=xlToLeft
    Columns("G:G").Select
    Selection.Delete Shift:=xlToLeft
    Columns("D:D").Select
    Selection.Cut
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Selection.Copy
    Columns("M:M").Select
    Selection.Insert Shift:=xlToRight
    Columns("C:C").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("N:N").Select
    Selection.Insert Shift:=xlToRight
    Columns("C:C").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("O:O").Select
    Selection.Insert Shift:=xlToRight
    Columns("C:C").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("P:P").Select
    Selection.Insert Shift:=xlToRight
    Range("N1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Category"
    Range("O1").Select
    ActiveCell.FormulaR1C1 = "Outages in min"
    Range("P1").Select
    ActiveCell.FormulaR1C1 = "15 mins"
    Range("N2").Select
    Selection.FormulaArray = _
        "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100),""No site outage"",IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100),""No Cell outage"",IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5,""Worst cell"",""Site outage"")))"
    Range("N2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("O2").Select
    Application.CutCopyMode = False
    Selection.FormulaArray = "=(100-AVERAGEIFS(C[-3],C[-13],RC[-2]))*24*60/100"
    Range("O2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("P2").Select
    Application.CutCopyMode = False
    Selection.FormulaArray = _
        "=IF(RC[-1]>15,""More than 15 mins"",""Within 15 mins"")"
    Range("P2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Application.CutCopyMode = False
    Selection.AutoFilter
    Sheets("ZTE").Select
    Range("B1").Select
    Selection.Copy
    Columns("E:E").Select
    Columns("B:B").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("E:E").Select
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    Selection.Copy
    Columns("M:M").Select
    Selection.Insert Shift:=xlToRight
    Range("K1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("K:K").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("N:N").Select
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    Selection.Copy
    Columns("O:O").Select
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    Selection.Copy
    Columns("P:P").Select
    Selection.Insert Shift:=xlToRight
    Range("N1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Category"
    Range("O1").Select
    ActiveCell.FormulaR1C1 = "OUTAGES IN MINS"
    Range("P1").Select
    ActiveCell.FormulaR1C1 = "15MINS"
    Range("N2").Select
    Selection.FormulaArray = _
        "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100),""No site outage"",IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100),""No Cell outage"",IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5,""Worst cell"",""Site Outage"")))"
    Range("N2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("O2").Select
    Application.CutCopyMode = False
    Selection.FormulaArray = "=(100-AVERAGEIFS(C[-3],C[-13],RC[-2]))*24*60/100"
    Range("O2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("P2").Select
    Application.CutCopyMode = False
    Selection.FormulaArray = _
        "=IF(RC[-1]>15,""More than 15 mins,""""Within15mins"")"
    Range("P2").Select
    Selection.FormulaArray = _
        "=IF(RC[-1]>15,""More than 15 mins"",""Within 15 mins"")"
    Range("P2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("M1").Select
    Application.CutCopyMode = False
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$P$1586").AutoFilter Field:=12, Criteria1:="0.00"
    Range("A168").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete
    Range("K1581").Select
    Selection.AutoFilter
    Range("A1").Select
    Sheets("HUAWEI").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$P$22388").AutoFilter Field:=12, Criteria1:="0"
    Range("A485").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete
    Range("K1").Select
    Selection.AutoFilter
    Range("A1").Select
    Sheets("ERICSON").Select
End Sub

2 个答案:

答案 0 :(得分:1)

我想我找到了你的问题,虽然我可能弄错了,因为我无法调试它。
此行

Selection.FormulaArray = _
        "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100),""No Site Outage"",IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100),""No Cell Outage"",IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5,""Worst Cell"",""Site Outage"")))"

可能会抛出错误,因为字符数超过255。
Related StackOverflow question
See Microsoft Support Article
可能对您有用的解决方法是这样的:

Selection.FormulaArray = _
        "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100)," & _
            """No Site Outage""," & _
            "IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100)," & _
                """No Cell Outage"",IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5," & _
                                        """Worst Cell""," & _
                                        """Site Outage"")))"

它计算由多个字符串组成的数组公式,每个字符串少于255个字符。

答案 1 :(得分:1)

(我正在扩大我对AntiDrondert对自己答案的回答。)

.FormulaArray属性最多只能接受255个字符。您可以使用.Replace方法解决此问题,但每个参数也只接受255个字符。 (只要你愿意,你可以重复它来制作数组中的公式)

我将更新您的第一个数组公式作为示例,以便您可以自己对其余部分进行匹配更改。

Range("N2").Select
Selection.FormulaArray = _
    "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100),""No Site Outage"",IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100),""No Cell Outage"",IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5,""Worst Cell"",""Site Outage"")))"
Range("N2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

现在,你的公式只略微超过(仍然不到300个字符),所以理论上我们只需要需要 1替换 - 但我会使用2来使你的每个IF块都是在另一条线上。

With Range("N2")
    'Each stage in the replace has to be a valid formula.  MAX(1) is short, and unusual, so easy to find/replace
    .FormulaArray = "=IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))=100,RC[-2]=100),""No Site Outage"",MAX(1))"
    .Replace "MAX(1)", "IF(AND(MIN(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))<100,RC[-2]=100),""No Cell Outage"",Max(1))"
    .Replace "MAX(1)", "IF(MAX(IF(RC[-1]=R2C2:R14829C2,R2C12:R14829C12))-RC[-2]>5,""Worst Cell"",""Site Outage"")"
End With
With Range(Range("N2"), Range("N2").End(xlDown))
    .FillDown
    .Calculate
    .Copy
    .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
End With