You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel VBA用AutoFilter提取OB表C、D列报错438如何解决?

错误原因及解决方案

触发438错误的核心问题

  • 拼写错误:代码中autfilter为拼写错误,正确属性名是AutoFilter,拼写错误导致VBA无法识别对应属性,触发对象不支持的报错
  • 缺少对象赋值关键字:fc是Range类型的对象,VBA中给对象赋值必须使用Set关键字,直接写fc = Intersect(...)不符合语法规则
  • 范围匹配不严谨:直接和整列C:D做交叉,会超出你预先定义的A3:E27数据源范围,可能带出不在业务范围内的冗余数据

修正后可运行的完整代码

Dim ob As Range, fc As Range
Set ob = Worksheets("ob").Range("a3:e27") 'source sheet
Sheet3.Range("A9:t155").ClearContents     'destination sheet
ob.Parent.AutoFilterMode = False
ob.AutoFilter Field:=1, Criteria1:="=" & Sheet3.Range("c2").Value       
' 修正拼写、加Set、限制在ob的行范围内取C、D列,同时只取过滤后的可见单元格
Set fc = Intersect(ob.SpecialCells(xlCellTypeVisible), ob.Parent.Range("C:D"))
fc.Copy
With Sheet3.Range("a9")                                              
    .PasteSpecial Paste:=8
    .PasteSpecial xlPasteValues
    .PasteSpecial xlPasteFormats
    Application.CutCopyMode = False
    .Select
End With
ob.Parent.AutoFilterMode = False

优化说明

增加了SpecialCells(xlCellTypeVisible)限定,只会复制过滤后可见的C、D列内容,避免把过滤隐藏的行也复制到目标表。

内容的提问来源于stack exchange,提问作者Raja V

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 07:24:05