If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Select method of range class failed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-30-06, 06:38
mikezcg mikezcg is offline
Registered User
 
Join Date: Oct 2003
Posts: 311
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
Reply With Quote
  #2 (permalink)  
Old 05-30-06, 06:53
norie norie is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 05-30-06, 08:38
mikezcg mikezcg is offline
Registered User
 
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?
Reply With Quote
  #4 (permalink)  
Old 05-30-06, 08:59
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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
Reply With Quote
  #5 (permalink)  
Old 05-30-06, 10:34
norie norie is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On