Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Runtime Error 1004 Select method of Range class Failed

I used the macro recorder to generate this code which worked without
errors:
Sheets("Larry").Select
Columns("D:D").Select
Selection.ClearContents
Sheets("Harry").Select
Columns("D:D").Select
Selection.ClearContents
Range("C1").Select

So I generalized it to be this:
For Each ws In ThisWorkbook.Worksheets
strWsName = ws.Name
Worksheets(strWsName).Select
Worksheets(strWsName).Activate
Columns("D:D").Select
Selection.ClearContents
Next ws

But on the 2nd worksheet the Columns("D:D").Select gives me the
error in the Subject of this message.

Sugestions please! How do get Excel to run this without complaining?

BTW: Column D in this context is a message area.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Runtime Error 1004 Select method of Range class Failed

Hi IanO,

It is rarely necessary or desirable to make physical selections. The
following code worked for me:

Sub Tester()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.Columns("D:D").ClearContents
Next ws
End Sub


---
Regards,
Norman



"IanO" wrote in message
oups.com...
I used the macro recorder to generate this code which worked without
errors:
Sheets("Larry").Select
Columns("D:D").Select
Selection.ClearContents
Sheets("Harry").Select
Columns("D:D").Select
Selection.ClearContents
Range("C1").Select

So I generalized it to be this:
For Each ws In ThisWorkbook.Worksheets
strWsName = ws.Name
Worksheets(strWsName).Select
Worksheets(strWsName).Activate
Columns("D:D").Select
Selection.ClearContents
Next ws

But on the 2nd worksheet the Columns("D:D").Select gives me the
error in the Subject of this message.

Sugestions please! How do get Excel to run this without complaining?

BTW: Column D in this context is a message area.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Runtime Error 1004 Select method of Range class Failed

Thanks Norman.
IanO

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
Runtime 1004 error -- insert method of range class failed. tish Excel Discussion (Misc queries) 1 June 1st 07 04:04 PM
RUNTIME ERROR '1004' --- Select method of worksheet class failed jawee Excel Programming 2 April 30th 04 06:47 AM
runtime error '1004' delete Method of Range Class Failed Tom Kennedy Excel Programming 0 April 14th 04 08:08 PM
Runtime Error "1004" Select Method of Range Class Failed Stephen[_7_] Excel Programming 4 April 10th 04 06:28 AM
excel97: runtime error 1004 select method of range class failed JMCN Excel Programming 4 December 25th 03 05:32 AM


All times are GMT +1. The time now is 04:17 PM.

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"