+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    07-24-2008
    Location
    San Antonio, Texas
    Posts
    94

    Run Time Error 1004 when selecting range on another sheet using a command button

    I have created a command button that plays the following macro.

    Code:
    Private Sub CommandButton1_Click()
        Sheets("Sheet2").Select
        Range("B10:C19").Select
    End Sub
    The command button is on Sheet1 and when I click the command button and the macro plays it will select Sheet2 and the range B10:C19, and returns a Run Time Error '1004': Select method of Range class failed.

    I have tried to play the macro without using the command button and it will select the range from Sheet2 without any problems/errors. I change the macro to select the range on Sheet1 and it works fine. I know the issue has something to do with the command button and can not figure it out.

    I am not sure what I am missing. Any help would be greatly appreciated.
    Last edited by randolphoralph; 11-20-2009 at 05:02 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Run Time Error 1004 when selecting range on another sheet using a command button

    Just add the sheet reference to the range...

    Code:
    Private Sub CommandButton1_Click()
        Sheets("Sheet2").Select
        Sheets("Sheet2").Range("B10:C19").Select
    End Sub
    The code is executing from Sheet1, so when Sheet2 is selected it is trying to select the range on Sheet1 (the Macro is not tied to the sheet, so that's why it works).

  3. #3
    Registered User
    Join Date
    07-24-2008
    Location
    San Antonio, Texas
    Posts
    94

    Thumbs up Re: Run Time Error 1004 when selecting range on another sheet using a command button

    It worked! Thank you so much

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.2.0