+ Reply to Thread
Results 1 to 8 of 8

"Select method of range class failed" error

Hybrid View

RBI "Select method of range class... 10-22-2008, 08:48 AM
royUK I would declare Bkst as a... 10-22-2008, 08:55 AM
rwgrietveld I do not see anything wrong... 10-22-2008, 09:00 AM
Andy Pope Assume recently opened... 10-22-2008, 09:16 AM
RBI Andy, I think you might... 10-22-2008, 09:37 AM
royUK I misread your initial code.... 10-22-2008, 09:48 AM
Andy Pope If you are running the code... 10-22-2008, 09:54 AM
RBI Semi fixed 10-22-2008, 10:28 AM
  1. #1
    Registered User
    Join Date
    09-13-2008
    Location
    Barrie, ON, CA
    Posts
    47

    "Select method of range class failed" error

    Hello,

    I have a macro that opens a specified woorkbook that changes every month. There are formulas which are pasted to range I1 of the new workbook to calculate the totals on this sheet. Everytime i run the code though, I get an error that says "Select method of range class failed" and Range("I1").Select is apparently the error. Here is the code... can anyone help?

    Private Sub CommandButton2_Click()
    Dim Bkst As Variant
    Bkst = Range("D27").Value
    Range("D47:F50").Copy
    Workbooks.Open Filename:="Q:\CRS PAID FILE (Lai-Yin)\STATEMENT OF ACCOUNT\2008\" & Bkst
      Range("I1").Select
       ActiveSheets.Paste
    End Sub
    Last edited by RBI; 10-22-2008 at 10:28 AM. Reason: mark as solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I would declare Bkst as a Range, not a Variant.

    Does the range actually have a value in it?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671
    I do not see anything wrong except that ActiveSheets.Paste
    should be ActiveSheet.Paste without the s
    Check if D27 contains data of this format Book1.xls and if the file is actually opened.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    Assume recently opened workbook as an activesheet that is,

    a worksheet and not a chart sheet
    is not protected so range I1 can be selected.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    09-13-2008
    Location
    Barrie, ON, CA
    Posts
    47
    Andy,

    I think you might have the answer there but im not quite sure i understand it fully... could you give me the code that your method is outlinning.

    Thanks
    Last edited by RBI; 10-22-2008 at 09:55 AM. Reason: Read new post after this thread

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I misread your initial code.

    Maybe

     Dim Bkst   As String
        Bkst = Workbooks("Operating Leases 08").Sheets("Adjustments").Cells(27, 4).Value
        Workbooks.Open Filename:="Q:\CRS PAID FILE (Lai-Yin)\STATEMENT OF ACCOUNT\2008\" & Bkst & ".xls" 'is .xls missing?
    'make sure the correct worksheet is used in target workbook
        Workbooks("Operating Leases 08").Range("D47:F50").Copy Workbooks(Bkst).Range("I1")

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    If you are running the code from a click event of a button on a worksheet make sure the button has the TakeFocusOnClick set to false.

  8. #8
    Registered User
    Join Date
    09-13-2008
    Location
    Barrie, ON, CA
    Posts
    47

    Semi fixed

    Hey guys,

    Aprreciate all the help... I still didn't figure it out so I made another macro that does the copy and pasting and called it at the end of the original macro... I used the same methods of refering to the newly opened workbook's range only this time it worked (go figure)...

    anyway Thanks again for the help

+ Reply to Thread

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.6.0 RC 1