Excel VBA错误'''对象不支持此属性或方法

时间:2018-06-12 03:53:56

标签: excel excel-vba excel-formula vba

我想在VBA中使用这个复杂的公式,但是,我一直收到错误,"描述"是其中一个标题'我的桌子上的名字,你能帮帮我吗?感谢。

现在它显示了两个错误,将表一直扩展到底部并且错误1004

Sub StartChecking()

'Spacing Check and Auto Correct

ActiveSheet.Range("O6").Formula = "=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(DVDQC_Log[@Description], ""/"", "" / "")), ""C / O"", ""C/O""), "" -"", ""-""), ""- "", ""-"")"    
Columns("O:O").EntireColumn.AutoFit
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("F6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
Application.CutCopyMode = False

'Pass or Fail Check

ActiveSheet.Range("P6").Formula = "=IF([DVDQC_Log[@Needed Revisions]]="", ""PASSED"", ""FAILED"")"
Columns("I:I").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$I1<>$P1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent2
    .TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("DVDQC_Log[[#Headers],[Notes]]").Select
Selection.Copy
Range("DVDQC_Log[[#Headers],[Pass/Fail]]").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="Address_ID", RefersToR1C1:= _
    "=DVDQC_Log[Address_ID]"
ActiveWorkbook.Names("Address_ID").Comment = ""
Columns("N:N").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=LEN(TRIM(N1))=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent2
    .TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("A6").Select
End Sub

1 个答案:

答案 0 :(得分:2)

基本上,你将一个公式放入一个细胞或一系列细胞中;没有进入工作表。看起来你的代码改编自Copy&amp;粘贴操作,您可以粘贴到ActiveSheet的默认ActiveCell。

如果O6是表格中的一个单元格,其中描述为列名称之一,那么

Sub StartChecking()

    ActiveSheet.Range("O6").Formula = _
        "=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE([@Description], ""/"", "" / "")), ""C / O"", ""C/O""), "" -"", ""-""), ""- "", ""-"")"
    ...
   Range(Range("O6"), Range("O6").End(xlDown)).Select
     ...
    ActiveSheet.Range("P6").Formula = _
        "=IF([DVDQC_Log[@Needed Revisions]]=text(,), ""PASSED"", ""FAILED"")"

End Sub

如果O6 表中的一个单元格,那么您还需要在[@Description]引用中包含表名,如Table1[@Description]