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

    Unanswered: Select method of range class failed

    This is CRAZY i have this sub in my sheet(1), i copied to sheet 2 and am using it from a btn Click event. i get the errror :
    Select method of range class failed
    runtime error 1004 on the 2nd row "Range("A3").Select" is this because the sub is in sheet 1 and i want it to work with another sheet?

    How can i call subs from this workbook, a modual from diff sheets? I konw it can be done just dont know how to qualify the sub

    Sub SetLastRow()
    Sheets("DataSet").Activate

    Range("A3").Select
    Selection.End(xlDown).Select
    LastRow = ActiveCell.Row
    End Sub

  2. #2
    Join Date
    Mar 2006
    Posts
    163
    The error is probably because you are running the code from a button.

    Does this work?
    Code:
    Sub SetLastRow()
         LastRow =Sheets("DataSet").Range("A3").End(xlDown)
    End Sub
    In Excel VBA you rarely have to select/activate ranges etc to work with them.

  3. #3
    Join Date
    Oct 2003
    Posts
    311
    I added .row and it works, why was there a problem? Maybe i should put all my code in a class and use that, would that solve the probl?

  4. #4
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi Mikezcg

    Yes, if you want to run code that relates to, or selects, different sheet than it should be in a Moduel, but not a CLASS Mode as you seem to suggest (that is a different object!).

    MTB

  5. #5
    Join Date
    Mar 2006
    Posts
    163
    mikezcg

    Using a class module is not the solution.

    The reason for the problem was because the selection when you pressed the button was the button itself.

Posting Permissions

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