Results 1 to 2 of 2

Thread: Range of Object failed?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Range of Object failed?

    Hi, the following code in my VBA program is causing a range of object failed error.
    VB Code:
    1. Range(Sheets(sheetname).Cells(start, startCol), Sheets(sheetname).Cells(50, startCol)).ClearContents

    It would only error if sheetname is not the current active sheet opened. Therefore I added
    VB Code:
    1. Range(Sheets(sheetname).Cells(start,startCol).Value, Sheets(sheetname).Cells(50,startCol).Value).Activate
    before it.
    It STILL complained! I ran out of ideas.
    Why wouldnt the compiler like the following code even after I activate the sheet?
    Last edited by mchow2469; Jul 26th, 2005 at 05:30 PM.

  2. #2
    Lively Member JustinLabenne's Avatar
    Join Date
    Jul 2005
    Location
    Ohio
    Posts
    64

    Re: Range of Object failed?

    This cleared the contents on my side

    VB Code:
    1. Option Explicit
    2.  
    3. Sub test()
    4. Dim sheetname As String
    5. Dim start
    6. Dim startcol
    7.  
    8.  
    9. sheetname = "MySheet"
    10. start = 1
    11. startcol = 2
    12.  
    13.  
    14. Range(Sheets(sheetname).Cells(start, startcol), Sheets(sheetname).Cells(50, startcol)).ClearContents
    15. End Sub


    What numbers are you using for Start/StartCol?
    Justin Labenne
    www.jlxl.net

Posting Permissions

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



Click Here to Expand Forum to Full Width