Home > Net >  Copying Range into new Workbook FileDialog prompt not working
Copying Range into new Workbook FileDialog prompt not working

Time:11-25

I'm trying to copy some specific cells to a new Workbook that I'm prompted to make while running the VBA script. I keep getting Object doesn't support this property or method on wsI.Range("Y2:AF2882), what's wrong with my code?

Option Explicit
Sub Export1()

    Dim wbI As Workbook, wbO As Workbook
    Dim wsI As Worksheet, wsO As Worksheet
    Dim Filename As Variant
    
    Set wbI = ThisWorkbook
    Set wbO = Workbooks.Add
    
    Filename = Application.GetSaveAsFilename(Filename, "Excelfile (*.xlsx), *.xlsx")


    With wbO
        Set wsO = wbO.Sheets("Ark1")
        Set wsI = wbI.Sheets("SVK stationer")
        .SaveAs Filename
        
        wsI.Range("Y2:AF2882") _
        .AutoFilter Field:=1, Criteria1:="<>"
        .SpecialCells(xlCellTypeVisible).Copy
       
        wsO.Range("A1").PasteSpecial (xlPasteValuesAndNumberFormats)
    End With
    
End Sub

CodePudding user response:

Updated re comments

Option Explicit
Sub Export1()

    Dim wb As Workbook
    Set wb = Workbooks.Add
    wb.Sheets(1).Name = "Arki"

    With ThisWorkbook.Sheets("SVK stationer").Range("Y2:AF2882")
        .AutoFilter Field:=1, Criteria1:="<>"
        .SpecialCells(xlCellTypeVisible).Copy
        wb.Sheets(1).Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
        wb.SaveAs Application.GetSaveAsFilename("", "Excelfile (*.xlsx), *.xlsx")
        'wb.Close False
    End With

End Sub
  • Related