Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: Range("A1").Select causes err 1004 Application-defined or object-defined error

    I am using 2007 the file is an xlsm file what the heck is wrong with 2007?

    Private Sub PersistValues()
    Dim lastDate As Date
    Dim todaysDate As Date

    Sheets("RateHistory").Activate
    Range("A1").Select <-- error

  2. #2
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    Where / what type of module is the code sitting in?

  3. #3
    Join Date
    Oct 2003
    Posts
    233
    its in sheet1 i guess i should move to mod

  4. #4
    Join Date
    Apr 2010
    Posts
    4
    One thing I noticed with 2007 is that it does not retain the active sheet the way older versions used to...

    For example:

    --- code to do something in the sheet that this code is in ---
    Range
    Cell
    etc..

    --- another sheet called active from code within this sheet ---
    with activesheet
    .range
    .cells
    .whatever
    Last edited by yoo_neek; 04-23-10 at 18:23.

  5. #5
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    Hi,

    Quote Originally Posted by mikezx10 View Post
    its in sheet1 i guess i should move to mod
    Yes exactly. You have not qualified the parent worksheet of the range which means it will belong to the worksheet that corresponds to that sheet class module. You can only select a range on the active sheet so unless that sheet happens to be the active sheet you will get an error. Either specify the parent sheet or move the code into a standard module to correct this.

    Of course, the other point to be made is that it is very uncommon to actually need to select a range with vba code... the range object can be worked with directly rather than working with the selection object. Doing it that way avoids issues such as the one you are seeing here and makes code run more quickly.
    Last edited by Colin Legg; 04-23-10 at 19:40.

Posting Permissions

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