设置从 VBA 中的 Copy() 方法返回的 Range 对象?
我已经使用宏在 Excel 2003 中的筛选列表范围上使用了 Copy() 方法,并且我想获取返回的范围并计算行数(这样我可以检查我是否复制了不止一行。但是我得到一个 '需要对象”错误。Microsoft
网站上的 VBA 参考资料告诉我,Copy() 方法返回一个范围对象,但从代码来看,情况并非如此,请告知
!
For J = 1 To .ListObjects.Count
' Filter
.ListObjects(J).Range.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=CritRange
Set CopiedRange = .ListObjects(J).Range.Copy ' Object required error
If CopiedRange.Rows.Count > 1 Then
{etc...}
I have used the Copy() method on a filtered List range in Excel 2003 using a macro and I want to grab the returned range and count the rows (so I can check I've copied more than one row. However I get an 'Object required' error.
I am told by VBA reference on Microsoft's website that the Copy() method returns a range object. However from the code this appears to not be the case. Please advise!
Thanks.
For J = 1 To .ListObjects.Count
' Filter
.ListObjects(J).Range.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=CritRange
Set CopiedRange = .ListObjects(J).Range.Copy ' Object required error
If CopiedRange.Rows.Count > 1 Then
{etc...}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Excel 不会在 Copy() 操作中返回范围对象。我尝试在复制之前测试行数的范围,但是如果不考虑特别是仅针对可见行,这是行不通的。因此,我需要编写一个新函数:
然后在复制之前在范围内测试它并确定要复制的行数(因为 Copy() 方法默认情况下仅复制可见行)。
Excel doesn't return a range object on a Copy() operation. I tried testing the range for the row count before copying it but this didn't work without taking into account especially for visible rows only. Hence I needed to write a new function:
I then tested this on the range before copying and determined the number of rows that would be copied (because the Copy() method copies only visible rows by default).