Share via

selection.insert shift:=xldown error when autofilter is on

Anonymous
2011-12-10T10:12:48+00:00

I have a sheet that has some filtered rows as per the code snippet below:

.Select

With .Range("A4:" & colRef & rowCount)

.AutoFilter

.AutoFilter Field:=FilterFieldYear, Criteria1:=strYear

.AutoFilter Field:=FilterFieldRegDiv, Criteria1:=strReg

.AutoFilter Field:=FilterFieldProgram, Criteria1:=strProg

End With

In another piece of code I get the error "insert method of range class failed" on the last line of code in the next code snippet.

Sheets("Action Plan").Activate

Sheets("Action Plan").Unprotect

Stop 'check if we need to add 1 to rowlocation when rows are filtered

Range("A" & rowLocation & ":" & colRef & rowLocation).Select

Selection.Insert Shift:=xlDown

So, how can I insert some cells if the above cells have an autofileter on it???

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-12-10T12:59:53+00:00

Hi,

add this

.Select

With .Range("A4:" & colRef & rowCount)

.AutoFilter

.AutoFilter Field:=FilterFieldYear, Criteria1:=strYear

.AutoFilter Field:=FilterFieldRegDiv, Criteria1:=strReg

.AutoFilter Field:=FilterFieldProgram, Criteria1:=strProg

End With


Range("A4").AutoFilter

.............

............

[Edit]

ok,

HansV replied to you.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-12-10T11:50:14+00:00

Turn off the AutoFilter, insert cells, then turn on the filter again.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2011-12-11T23:51:10+00:00

    Thanks Hans and Tasos - worked a treat.

    Was this answer helpful?

    0 comments No comments