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;
The new workbook opens but then the error comes. I checked and there is no paste option so nothing is on the clipboard.Code:rng.Columns("C:H").SpecialCells(xlCellTypeVisible).Copy Destination:=newWorkBook.Sheet1.Range("A1")
Full code is below;
Do I need to fully qualify the original workbook because the new workbook is open? If so, how to do that?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
Thanks




Reply With Quote