Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA error 1004 "Select method of Range class failed"

I have the following code in a Macro for deleting a range of cells and it works fine but when I use it in a click event for a command button I receive the error.

Sheets("SOAUDITSO").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

I know it is something simple. I am new to VBA so please excuse my ignorance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default VBA error 1004 "Select method of Range class failed"

If you're using XL97, you have to set the button's Take Focus on Click
property to False.

But you don't need to do all those selections. Try:

With Sheets("SOAUDITSO").Range("2:2")
Range(.Cells, .Cells.End(xlDown)).Delete
End With

Using the Range objects directly makes your code smaller, faster and,
IMO, easier to maintain.


In article ,
Matt J wrote:

I have the following code in a Macro for deleting a range of cells and it
works fine but when I use it in a click event for a command button I receive
the error.

Sheets("SOAUDITSO").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

I know it is something simple. I am new to VBA so please excuse my
ignorance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA error 1004 "Select method of Range class failed"

Sorry for the duplicate I got an error when it was posting

"Matt J" wrote:

I have the following code in a Macro for deleting a range of cells and it works fine but when I use it in a click event for a command button I receive the error.

Sheets("SOAUDITSO").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

I know it is something simple. I am new to VBA so please excuse my ignorance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA error 1004 "Select method of Range class failed"

Tried it.

1004 error changed to "Method 'Range' of object_'Worksheet' failed"


"JE McGimpsey" wrote:

If you're using XL97, you have to set the button's Take Focus on Click
property to False.

But you don't need to do all those selections. Try:

With Sheets("SOAUDITSO").Range("2:2")
Range(.Cells, .Cells.End(xlDown)).Delete
End With

Using the Range objects directly makes your code smaller, faster and,
IMO, easier to maintain.


In article ,
Matt J wrote:

I have the following code in a Macro for deleting a range of cells and it
works fine but when I use it in a click event for a command button I receive
the error.

Sheets("SOAUDITSO").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

I know it is something simple. I am new to VBA so please excuse my
ignorance.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default VBA error 1004 "Select method of Range class failed"

Are you running the code from the same worksheet as Sheet SOAUDITSO?


In article ,
Matt J wrote:

1004 error changed to "Method 'Range' of object_'Worksheet' failed"



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA error 1004 "Select method of Range class failed"

No, it is a click event in another sheet

"JE McGimpsey" wrote:

Are you running the code from the same worksheet as Sheet SOAUDITSO?


In article ,
Matt J wrote:

1004 error changed to "Method 'Range' of object_'Worksheet' failed"


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA error 1004 "Select method of Range class failed"

GOT IT!

Took your code and set it into a separate public subprocedure ...
Sheets("SOAUDITITEM").Select
Call PubProcedure.pcdrClearSheet
Application.Goto Reference:="R2C1"

I just select the sheets and call the subprocedure.

thanks for your help.

"Matt J" wrote:

No, it is a click event in another sheet

"JE McGimpsey" wrote:

Are you running the code from the same worksheet as Sheet SOAUDITSO?


In article ,
Matt J wrote:

1004 error changed to "Method 'Range' of object_'Worksheet' failed"


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
"Select method of Range class failed" Error Ayo Excel Discussion (Misc queries) 3 September 2nd 08 07:58 PM
Run-time error "1004" Select method of range class failed Tallan Excel Discussion (Misc queries) 3 March 7th 07 05:22 PM
Error 1004, "select method of range class failed" paritoshmehta[_11_] Excel Programming 3 May 6th 04 10:09 PM
Runtime Error "1004" Select Method of Range Class Failed Stephen[_7_] Excel Programming 4 April 10th 04 06:28 AM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM


All times are GMT +1. The time now is 06:25 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"