Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1836|回复: 1

[已解决]错误1004

[复制链接]
发表于 2012-8-7 10:28 | 显示全部楼层 |阅读模式
Sub inventory1()
Dim InR As Long
Dim x As Long
Intersect(ActiveSheet.UsedRange, [E4:E65536]).SpecialCells(4).Delete 3
lngR = Range("A65536").End(xlUp).Row
x = ActiveSheet.[IV1].End(xlToLeft).Column
For j = 1 To x
If InStr(Cells(1, x), "CXST Cat") > 0 Then
x1 = x
End If
If InStr(Cells(1, x), "CXST SubCat") > 0 Then
x2 = x
End If
Next j
程序运行到lngR = Range("A65536").End(xlUp).Row就发生错误1004 求大神帮忙啊
最佳答案
2012-8-7 16:26
Intersect(ActiveSheet.UsedRange, [E1:E65536]).SpecialCells(4).Delete 3
这句代码有问题,如果你的Intersect函数不能返回有效区域,也就是Intersect(ActiveSheet.UsedRange, [E1:E65536])为Nothing的情况下就会报错1004

为了避免出现这样的问题,
可以这么写
If not Intersect(ActiveSheet.UsedRange, [E1:E65536]) is nothing then Intersect(ActiveSheet.UsedRange, [E1:E65536]).SpecialCells(4).Delete 3
发表于 2012-8-7 16:26 | 显示全部楼层    本楼为最佳答案   
Intersect(ActiveSheet.UsedRange, [E1:E65536]).SpecialCells(4).Delete 3
这句代码有问题,如果你的Intersect函数不能返回有效区域,也就是Intersect(ActiveSheet.UsedRange, [E1:E65536])为Nothing的情况下就会报错1004

为了避免出现这样的问题,
可以这么写
If not Intersect(ActiveSheet.UsedRange, [E1:E65536]) is nothing then Intersect(ActiveSheet.UsedRange, [E1:E65536]).SpecialCells(4).Delete 3
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-4 23:02 , Processed in 0.222189 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表