+ Reply to Thread
Results 1 to 13 of 13

Thread: Range.clear failure

  1. #1
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Range.clear failure

    Hi, i'm creating an excel front end for an access db and currently the getting data bit is working nicely..

    so i was happily coding away until this happened!:


     Sheets("Edit Package").Range("D9").Clear
      
      rst.Open "Select [Channel Brand] From ChannelBrandPackageLink where [Package ID] = " & Cells(9, 2).Value, conn
      
          
      Sheets("Edit Package").Range("D9").CopyFromRecordset rst
    and the range.clear failed... this is irratating as if i remove it it will leave aspects on the page and be confusing for both the program and the user :-(

    and chance you can point me in the right direction?

    thanks!

    Jonathan
    Last edited by Jollyfrog; 10-06-2010 at 12:15 PM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Range.clear failure

    Failed how? Error, explosion, sudden rain of jelly? If by chance it was an error, what was the error message?

  3. #3
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    i get a "class method of range class failed!"

    i assumed i'd only get that if i called a sheet which wasn't the active one .. apparently this isn't the case!

    thanks

  4. #4
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Range.clear failure

    I suppose your intention is to clear the contents of a given cell:

    Sheets("Edit Package").Range("D9").Clearcontents
    I can't think of any error message in this case unless the sheet doesn't exist, the cell is protected or part of an array.



  5. #5
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    Thanks tried that, its not protected, and i removed any associated security and formatting, validation, associated with the cell and ran the code again!, but same error

  6. #6
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Range.clear failure

    What happens if you try to empty this cell manually ?

    (is a querytable connected to this cell ?)



  7. #7
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    Removing content manually works fine! and it is not connected to a query table

  8. #8
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    i alos tried

    
    Range("D10").Select
      
      Selection.ClearContents
    but this produces the same error!

  9. #9
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Range.clear failure

    Are you sure the name Sheets("Edit Package") is written correctly ?
    Are several workbook open ? In that case you should mention the workbook too:

    Workbooks("opened.xls").Sheets("Edit Package").range("D8").clearcontents
    another approach:

    Record a macro emptying this cell; compare the recorded macro with you current code.



  10. #10
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    the code gives me the error, subset out of range!


    i tried a macro which gave me the code:

    Range("D10").Select
      
    Selection.ClearContents
    but this errors too when i use it!

  11. #11
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    hmm when i use the code
     Workbooks("package.xlsm").Sheets("Edit Package").Range("D9").ClearContents
    as a seperate function it seems to work ok...

    must be an issue somewhere else in my code

    Private Sub TempCombo_Change()
    
     
      Dim conn As New ADODB.Connection
      Dim sNWind As String
      Dim rst As New ADODB.Recordset
      
      
      
     sNWind = _
          "M:\Television and Broadband\CHANNEL ECONOMICS\Database\Database Actual\ChannelEconomics.accdb"
          
       conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
          sNWind & ";"
      
      rst.Open "Select [Package Name] From Package where Operator = '" & Cells(2, 6).Value & "'", conn
      
      Sheets("Edit Package").Range("l1").CopyFromRecordset rst
        
      rst.Close
      
      
      
      If Cells(2, 7).Value <> 0 Then
      
      rst.Open "Select [Package Name] From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B1").CopyFromRecordset rst
        
      rst.Close
      
      rst.Open "Select Operator From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B2").CopyFromRecordset rst
        
      rst.Close
      
      rst.Open "Select [Tier Level] From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B3").CopyFromRecordset rst
        
      rst.Close
      
      rst.Open "Select [Subscription Fee] From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B4").CopyFromRecordset rst
          
      rst.Close
      
      rst.Open "Select [Digital/Analogue] From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B5").CopyFromRecordset rst
          
      rst.Close
      
      rst.Open "Select [Package Date] From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B6").CopyFromRecordset rst
        
      rst.Close
      
      rst.Open "Select [subscriber %] From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B7").CopyFromRecordset rst
        
      rst.Close
      
      rst.Open "Select active From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B8").CopyFromRecordset rst
        
      rst.Close
      
      rst.Open "Select ID From Package where Operator = '" & Cells(2, 6).Value & "' and [Package Name] = '" & Cells(2, 7).Value & "'", conn
      Sheets("Edit Package").Range("B9").CopyFromRecordset rst
        
      rst.Close
      
      
      
      
      'Range("D10").Select
      
      'Selection.ClearContents
      
      'Sheets("Edit Package").Range("D10").Clear
      
      Workbooks("package.xlsm").Sheets("Edit Package").Range("D9").ClearContents
      
      rst.Open "Select [Channel Brand] From ChannelBrandPackageLink where [Package ID] = " & Cells(9, 2).Value, conn
      
      
        
      Sheets("Edit Package").Range("D9").CopyFromRecordset rst
      
     
      
          
      rst.Close
    
    End If
    
    
    
    
      
      Set rsData = Nothing
      Set dbData = Nothing
    
    
    End Sub

  12. #12
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Range.clear failure

    the code gives me the error, subset out of range!
    I bet you got that because you didn't adapt my code (or it would be a rare coincidence that one of the opend workbooks is called 'opened.xls'

    I think it's time to put your workbook here and tell us how many workbooks are opened at the same time the macro is running and where you store the macro you are running.



  13. #13
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Range.clear failure

    what the..... now it works..

    i opened a different workbook to do something else and then came back to it and it worked..... i've been on this since yesterday

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0