Prezados amigos, preciso de uma ajuda! Criei um codigo em VBA para copiar e colar os dados de pedidos de clientes de uma planilha para outra. E cada vez que a macro roda preenche a planilha de historico na linha de baixo.
Acontece que ele dá erro na linha em negrito, só que se finalizo o depurador e executo a macro novamente ela roda corretamente...
O erro que acontece é o 1004- Tempo de execucao - erro de definicao de aplicativo ou de definicao de objeto
Sub Confirmar_Pedido()
'
' Confirmar_Pedido Macro
'
' Atalho do teclado: Ctrl+Shift+C
Dim cont As Long
cont = Range("AU1").Value
Sheets("Historico").Select
ActiveSheet.Range("B3").Select
ActiveCell.Offset(cont, 3).Select
Sheets("Pedido").Select
Range("L6:M6").Select
Selection.Copy
Sheets("Historico").Select
Cells(cont, 2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("M4").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("L8:M8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 5).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("S1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 7).Select
ActiveSheet.Paste
Sheets("Pedido").Select
Range("L10:O10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, .Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("P10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 13).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("Q10:S10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 14).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("L12:M12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 17).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("N12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 19).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("R6:S6").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 20).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Carretilhas").Select
Range("D8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 22).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("T:T").ColumnWidth = 15
Cells(cont, 23).Select
Sheets("Carretilhas").Select
Range("E8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 24).Select
Sheets("Carretilhas").Select
Range("D9").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Carretilhas").Select
Range("E9").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 25).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
Cells(cont, 26).Select
ActiveCell.FormulaR1C1 = ""
Sheets("Carretilhas").Select
Range("D10").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Carretilhas").Select
Range("E10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 27).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 28).Select
Sheets("Carretilhas").Select
Range("D11").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Carretilhas").Select
Range("E11").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 29).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 30).Select
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 18
Sheets("Varas").Select
Range("D8").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 31).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 32).Select
Sheets("Varas").Select
Range("D9").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E9").Select
Application.CutCopyMode = False
Selection.Copy
Cells(cont, 33).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 31).Select
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 33).Select
Selection.Style = "Currency"
Columns("AG:AG").EntireColumn.AutoFit
Columns("AG:AG").ColumnWidth = 12
Cells(cont, 34).Select
Sheets("Varas").Select
Range("D10").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 35).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 36).Select
Sheets("Varas").Select
Range("D11").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Cells(cont, 37).Select
Sheets("Varas").Select
Range("E11").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 38).Select
Sheets("Varas").Select
Range("D12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Cells(cont, 39).Select
Sheets("Varas").Select
Range("E12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Cells(cont, 39).Select
Sheets("Varas").Select
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 40).Select
Sheets("Varas").Select
Range("D13").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E13").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 41).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 21
ActiveWindow.ScrollColumn = 23
ActiveWindow.ScrollColumn = 24
ActiveWindow.ScrollColumn = 25
Sheets("Varas").Select
Range("D14").Select
Selection.Copy
Sheets("Historico").Select
Cells(cont, 42).Select
ActiveSheet.Paste
Cells(cont, 43).Select
Sheets("Varas").Select
Range("E14").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 44).Select
Sheets("Pedido").Select
Range("S15").Select
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Selection.Style = "Currency"
Cells(cont, 45).Select
Sheets("Pedido").Select
ActiveWindow.SmallScroll Down:=15
Range("S30").Select
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Sheets("Pedido").Select
ActiveWindow.SmallScroll Down:=-3
Range("M17").Select
Selection.Copy
Sheets("Historico").Select
Cells(cont, 46).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Acontece que ele dá erro na linha em negrito, só que se finalizo o depurador e executo a macro novamente ela roda corretamente...
O erro que acontece é o 1004- Tempo de execucao - erro de definicao de aplicativo ou de definicao de objeto
Sub Confirmar_Pedido()
'
' Confirmar_Pedido Macro
'
' Atalho do teclado: Ctrl+Shift+C
Dim cont As Long
cont = Range("AU1").Value
Sheets("Historico").Select
ActiveSheet.Range("B3").Select
ActiveCell.Offset(cont, 3).Select
Sheets("Pedido").Select
Range("L6:M6").Select
Selection.Copy
Sheets("Historico").Select
Cells(cont, 2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("M4").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("L8:M8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 5).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("S1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 7).Select
ActiveSheet.Paste
Sheets("Pedido").Select
Range("L10:O10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, .Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("P10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 13).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("Q10:S10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 14).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("L12:M12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 17).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("N12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 19).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pedido").Select
Range("R6:S6").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 20).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Carretilhas").Select
Range("D8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 22).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("T:T").ColumnWidth = 15
Cells(cont, 23).Select
Sheets("Carretilhas").Select
Range("E8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 24).Select
Sheets("Carretilhas").Select
Range("D9").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Carretilhas").Select
Range("E9").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 25).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
Cells(cont, 26).Select
ActiveCell.FormulaR1C1 = ""
Sheets("Carretilhas").Select
Range("D10").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Carretilhas").Select
Range("E10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 27).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 28).Select
Sheets("Carretilhas").Select
Range("D11").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Carretilhas").Select
Range("E11").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 29).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 30).Select
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 18
Sheets("Varas").Select
Range("D8").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 31).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 32).Select
Sheets("Varas").Select
Range("D9").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E9").Select
Application.CutCopyMode = False
Selection.Copy
Cells(cont, 33).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 31).Select
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 33).Select
Selection.Style = "Currency"
Columns("AG:AG").EntireColumn.AutoFit
Columns("AG:AG").ColumnWidth = 12
Cells(cont, 34).Select
Sheets("Varas").Select
Range("D10").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 35).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 36).Select
Sheets("Varas").Select
Range("D11").Select
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Cells(cont, 37).Select
Sheets("Varas").Select
Range("E11").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 38).Select
Sheets("Varas").Select
Range("D12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Cells(cont, 39).Select
Sheets("Varas").Select
Range("E12").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Cells(cont, 39).Select
Sheets("Varas").Select
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells(cont, 40).Select
Sheets("Varas").Select
Range("D13").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
ActiveSheet.Paste
Sheets("Varas").Select
Range("E13").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Cells(cont, 41).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 21
ActiveWindow.ScrollColumn = 23
ActiveWindow.ScrollColumn = 24
ActiveWindow.ScrollColumn = 25
Sheets("Varas").Select
Range("D14").Select
Selection.Copy
Sheets("Historico").Select
Cells(cont, 42).Select
ActiveSheet.Paste
Cells(cont, 43).Select
Sheets("Varas").Select
Range("E14").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Cells(cont, 44).Select
Sheets("Pedido").Select
Range("S15").Select
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Selection.Style = "Currency"
Cells(cont, 45).Select
Sheets("Pedido").Select
ActiveWindow.SmallScroll Down:=15
Range("S30").Select
Selection.Copy
Sheets("Historico").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Style = "Currency"
Sheets("Pedido").Select
ActiveWindow.SmallScroll Down:=-3
Range("M17").Select
Selection.Copy
Sheets("Historico").Select
Cells(cont, 46).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub