Problem with Range Object

G

Guest

I sometimes get an error with this code. The error says:

"Run-time error '1004':

THe command could not be completed by using the range specified. Select a
single cell within the range and try the command again."

The object is not empty, and it has a valid range. What does this error
mean, and why does it not happen every time?

Code:

Dim typeCol As Integer, typeRng As Range

' Reset these values to fit the correct columns
typeCol = 8
lastRow = Cells(65536, 1).End(xlUp).Row

' Define Ranges
Set typeRng = Range(Cells(2, typeCol), Cells(lastRow, typeCol))

' Create unique list of used types
typeRng.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"I2"), Unique:=True
Range("I2").Select

Thanks,
Pflugs
 
V

Vasant Nanavati

It would be helpful if you would specify which line of code throws the
error.

Just a guess, but have you tried to use a fully qualified range (i.e.,
including the worksheet reference)?
_______________________________________________________________________
 
G

Guest

Yes, adding the sheet reference to the declaration seems to help. The macro
was failing as I tried to apply the Advanced Filter.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top