Hi guys,
Can anyone help me?
I'm trying to make this code copy a range to clipboard and than paste it as .PasteEspecial but i'm geting an error.
Error: 1004
Application-defined or Object-defined error
Heres the code:
Sub DividirParaConquistar()
Application.CutCopyMode = False
Application.ScreenUpdating = False
Dim wsDestino As Workbook
Dim rng As Range
ContagemCriterios = Worksheets("Configuração").Range("E101").Value
Pasta = Worksheets("Configuração").Range("B12").Value
NomePre = Worksheets("Configuração").Range("B08").Value
NomePos = Worksheets("Configuração").Range("B10").Value
Y = Worksheets("Configuração").Range("B6").Value
CabCol = Worksheets("Configuração").Range("B2").Value
CabLin = Worksheets("Configuração").Range("B4").Value
For x = 1 To ContagemCriterios
Criterio = Worksheets("Configuração").Range("E" & 2 + x).Value
Set wsDestino = Application.Workbooks.Add
wsDestino.SaveAs Filename:= _
Pasta & "\" & NomePre & Criterio & NomePos & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
wsDestino.Activate
'NOVO
Workbooks("Divisor 2.0.xlsm").Worksheets("div").Range(Cells(1, 1), Cells(CabLin, CabCol)).Copy <<< ERROR IN THIS LINE
With wsDestino.Worksheets(1).Range(Sheets(1).Cells(1, 1), Sheets(1).Cells(CabLin, CabCol))
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteColumnWidths
End With
Workbooks("Divisor 2.0.xlsm").Worksheets("div").Range(Sheets("Configuração").Cells(CabLin, 1), Sheets("Configuração").Cells(100000, CabCol)).AutoFilter Field:=Y, Criteria1:=Criterio, _
Operator:=xlAnd
Workbooks("Divisor 2.0.xlsm").Worksheets("div").Range(Cells(CabLin + 1, 1), Cells(100000, CabCol)).SpecialCells(xlCellTypeVisible).Copy Destination:=wsDestino.Application.Worksheets(1).Range(Cells(CabLin + 1, 1))
wsDestino.Save
wsDestino.Close savechanges:=True
Next
Application.StatusBar = False
End Sub
Thank you guys.
Bookmarks