+ Reply to Thread
Results 1 to 3 of 3

Runtime Error 1004 Select method of Range class Failed

  1. #1
    IanO
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >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. #3
    IanO
    Guest

    Re: Runtime Error 1004 Select method of Range class Failed

    Thanks Norman.
    IanO


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1