VBA代码在1台计算机上运行,​​但在另一台计算机上给出语法错误

时间:2019-05-02 21:49:04

标签: excel vba

我在下面记录了该宏,它在我的计算机上运行良好(Excel 2016)。但是,当我使用excel 2013在另一台计算机上运行它时,它给我“语法错误”并突出显示公式以计算列V“状态”。它似乎也跳过了之前的所有内容,这意味着不添加2个新列,也不计算U列“日期”。关于如何解决此问题的任何想法?我不知道2个excel版本之间的语法差异。谢谢!

 Sub ReportingStatus()

    Dim LastRow As Range

    'Add 2 columes and format them
    Range("U6").Select
        ActiveCell.FormulaR1C1 = "Dates"
        Range("V6").Select
        ActiveCell.FormulaR1C1 = "Status"

        Range("T6").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("U6:V6").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False

        Range("S65536").End(xlUp).Select
        ActiveCell.Offset(0, 2).Select
        Set LastRow = ActiveCell

    'Calculate the value for column U "Date"
        Application.ScreenUpdating = False
        Range("U7", LastRow).Select

        Selection.FormulaR1C1 = _
            "=IF(RC[-2]=""Awaiting Management Response"",R2C1-RC[-9],IF(RC[-3]<>"""",MAX(RC[-3]-RC[-4],R2C1-RC[-3]),R2C1-RC[-4]))"

        LastRow.Offset(0, 1).Select

    'Calculate the value for column V "Status"
        Range("V7", ActiveCell).Select
        Selection.FormulaR1C1 = _
            "=IF(RC[-3]=""Awaiting Management Response"",IF(RC[-1]<1,""MGMT-CURRENT"",IF(AND(1<=RC[-1],RC[-1]<=60),""MGMT-DELAYED"",IF(AND(61<=RC[-1],RC[-1]<=90),""MGMT-SIGNIFICANTLY DELAYED"",""MGMT-CRITICAL""))),IF(RC[-1]<1,""CURRENT"",IF(AND(1<=RC[-1],RC[-1]<=60),""DELAYED"",IF(AND(61<=RC[-1],RC[-1]<=90),""SIGNIFICANTLY DELAYED"",""CRITICAL""))))"
        Range("V7").Select

        Columns("U:V").EntireColumn.AutoFit

0 个答案:

没有答案