Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Run-time error '1004': Insert method of Range class failed

Hello, all:

I keep getting this Error 1004 in my macro.

This portion of the macro filters a selection, selects only the visible
cells, and inserts new entire rows. I've tried coding it different ways, and
always I get the same error. Here is the section of code:

Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="1"
Range("A2:R2044").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.EntireRow.Insert

It hangs up on the last line of code. I posted something about this earlier
but didn't get much help--any assistance would be greatly appreciated, as I'm
sure it is a quick fix. Thanks again!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Run-time error '1004': Insert method of Range class failed

I'd check to see if anything was selected

Try replacing the last line of code with this

If Selection is nothing then
MsgBox("There was no selection")
else
Selection.EntireRow.Insert
End If

Alternatively, you could use

On Error resume next
Selection.EntireRow.Insert
On Error goto 0

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"jerryb123" wrote:

Hello, all:

I keep getting this Error 1004 in my macro.

This portion of the macro filters a selection, selects only the visible
cells, and inserts new entire rows. I've tried coding it different ways, and
always I get the same error. Here is the section of code:

Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="1"
Range("A2:R2044").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.EntireRow.Insert

It hangs up on the last line of code. I posted something about this earlier
but didn't get much help--any assistance would be greatly appreciated, as I'm
sure it is a quick fix. Thanks again!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Run-time error '1004': Insert method of Range class failed

You can try this...

dim rngVisible as range
dim rng as range

Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="1"
on error resume next
set rngVisible = Range("A2:R2044").SpecialCells(xlCellTypeVisible)
on error goto 0

If Not rngVisible Is Nothing Then
For Each rng In rngVisible.Areas
rng.EntireRow.Insert
Next rng
End If
--
HTH...

Jim Thomlinson


"jerryb123" wrote:

Hello, all:

I keep getting this Error 1004 in my macro.

This portion of the macro filters a selection, selects only the visible
cells, and inserts new entire rows. I've tried coding it different ways, and
always I get the same error. Here is the section of code:

Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="1"
Range("A2:R2044").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.EntireRow.Insert

It hangs up on the last line of code. I posted something about this earlier
but didn't get much help--any assistance would be greatly appreciated, as I'm
sure it is a quick fix. Thanks again!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 10 April 16th 09 09:06 PM
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 3 April 14th 09 10:35 PM
Runtime 1004 error -- insert method of range class failed. tish Excel Discussion (Misc queries) 1 June 1st 07 04:04 PM
Run-Time error '1004' : Select method of Range class failed [email protected] Excel Discussion (Misc queries) 3 March 9th 07 01:36 PM
Select method of range class failed, Run time error 1004 smit127 Excel Programming 1 September 1st 05 12:43 PM


All times are GMT +1. The time now is 02:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"