Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange Code Behaviour (2000)

    The code below was generated with the macro creator. if this is in a normal macro, and assigned to a normal button it works fine.
    However, if you copy this code and add it to the code event of a command button, it generates an error.
    <font color=red>"Run time error 1004. Select method of range class failed."</font color=red>

    <font color=blue>Sheets("Part1").Select
    Range("A21:AI2000").Select
    Selection.ClearContents
    Sheets("Part2").Select
    Range("A21:V2000").Select
    Selection.ClearContents
    Sheets("Part3").Select
    Range("A21:BB2000").Select
    Selection.ClearContent</font color=blue>

    why is this ?

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Strange Code Behaviour (2000)

    Try this:
    Steve
    <pre>Sheets("Part1").Range("A21:AI2000").ClearCont ents
    Sheets("Part2").Range("A21:V2000").ClearContents
    Sheets("Part3").Range("A21:BB2000").ClearContents
    </pre>


  3. #3
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,822
    Thanks
    134
    Thanked 481 Times in 458 Posts

    Re: Strange Code Behaviour (2000)

    If the Select method failed have you tried not using it, e.g try

    Sheets("Part1").Range("A21:AI2000").ClearContents
    Sheets("Part2").Range("A21:V2000").ClearContents
    Sheets("Part3").Range("A21:BB2000").ClearContents

    zeddy

  4. #4
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Code Behaviour (2000)

    Wow .. i got the double !!! look at the time of the previous 2 posts and the contents.

    Thanks for the code guys.. i wasn kinda interested why the code doesn't work though.....

    it works in a normal macro, if assigned to a button. but not if the same code is assigned to a command button. <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

    this, to me, is very very stupid, and very very Micro$oft. i was just wondering if it was related to not having enabled the Doogery-Flip command access-x-library-version-3.6 (or something equally as insane) <img src=/S/clown.gif border=0 alt=clown width=15 height=15>

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Code Behaviour (2000)

    It fails because in the click event, the active object is the button, not a worksheet.
    Legare Coleman

  6. #6
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,822
    Thanks
    134
    Thanked 481 Times in 458 Posts

    Re: Strange Code Behaviour (2000)

    I knew you know that.

    zeddy

Posting Permissions

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