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...}
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).