Results 1 to 6 of 6

Thread: [RESOLVED] error when pasting to a new workbook

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2012
    Posts
    90

    [RESOLVED] error when pasting to a new workbook

    Hi

    I have a routine that copies filtered records from a worksheet into a new workbook. Everything was working fine and then it stopped and I don't see why. Error is '438 0 object doesn't support this property or method'.

    The error is happening on the line;

    Code:
    rng.Columns("C:H").SpecialCells(xlCellTypeVisible).Copy Destination:=newWorkBook.Sheet1.Range("A1")
    The new workbook opens but then the error comes. I checked and there is no paste option so nothing is on the clipboard.

    Full code is below;
    Code:
    Dim wbSaveAs As String
    Dim wbSaveName As String
    Dim newWorkBook As Workbook
    Dim rng As Range
    
    wbSaveName = Sheet4.Range("F4").Value
    wbSaveAs = Sheet4.Range("F3").Value & wbSaveName
    
    Set rng = Sheet1.ListObjects("PickList").AutoFilter.Range
    
         With Sheet1.Range("Picklist[#All]")
            
            Sheet1.ListObjects("PickList").Range.advancedfilter xlFilterInPlace, CriteriaRange:=Sheet4.Range("H1:J3"), Unique:=False
            
            Sheet1.Unprotect
            If rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 > 0 Then
                
                If WorkbookIsOpen(wbSaveName) Then
                    MsgBox "The workbook " & wbSaveAs & " is already open." & vbCr & vbCr & "Please close it and click Export once more.", vbInformation + vbDefaultButton1 + vbOKOnly, "Export"
    
    ' check if filters are active for the PICKLIST range and if not then set then on so that all records are
    ' displayed otherwise show all records anyway
    
                    Exit Sub
                End If
    
                lblLastExport.Caption = "Creating Workbook"
                
                Set newWorkBook = Workbooks.Add
                With newWorkBook
                
                    lblLastExport.Caption = "Copying Rows to New Workbook"
     
    ' ERROR is happening on this line           
                    rng.Columns("C:H").SpecialCells(xlCellTypeVisible).Copy Destination:=newWorkBook.Sheet1.Range("A1")
                   
                    lblLastExport.Caption = "Finished Copying Workbook"
                    
                    .SaveAs Filename:=wbSaveAs, FileFormat:=xlNormal, CreateBackup:=False
                    .Close Savechanges:=False
           
                    lblLastExport.Caption = "Workbook Created"
                
                End With
       
            End If
    Do I need to fully qualify the original workbook because the new workbook is open? If so, how to do that?

    Thanks
    Last edited by scoobster; Jul 17th, 2012 at 02:24 AM. Reason: is now resolved

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