Мой код работает, как я хочу, но только в рабочей книге.
Я хочу перенести данные в другую книгу, но если я изменяю имя и путь, это не работает.
EG: in код где это
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 2)
я использовал ->
Worksheets("SHIPMENTS").Paste
Destination:=Workbooks("Name").Worksheets("SheetName").Cells(b + 1, 2)"
и он не работал.
Код выглядит так:
Private sub BTN
a = Worksheets("SHIPMENTS").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
'based by country
If Worksheets("SHIPMENTS").Cells(i, 5).Value = "SI" Then
'if already sent
If Worksheets("SHIPMENTS").Cells(i, 9).Value = "YES" Then
'sorting by color
If Worksheets("SHIPMENTS").Cells(i, 5).Interior.Color = 16777215 Then
'kopiranje (datuma)
Worksheets("SHIPMENTS").Cells(i, 3).Copy
'counting
b = Worksheets("SI").Cells(Rows.Count, 1).End(xlUp).Row
'paste 1
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 1)
'copy paste
'country
Worksheets("SHIPMENTS").Cells(i, 5).Copy
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 2)
'quty
Worksheets("SHIPMENTS").Cells(i, 10).Copy
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 3)
'transfer note
Worksheets("SHIPMENTS").Cells(i, 6).Copy
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 4)
'transfer number
Worksheets("SHIPMENTS").Cells(i, 8).Copy
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 5)
'month
Worksheets("SHIPMENTS").Cells(i, 12).Copy
Worksheets("SHIPMENTS").Paste Destination:=Worksheets("SI").Cells(b + 1, 7)
'coloring
Worksheets("SHIPMENTS").Cells(i, 5).Interior.ColorIndex = 43
'to the first position
Worksheets("SHIPMENTS").Activate
End If
End If
End If
Next
MsgBox "Copied"
Application.CutCopyMode = True
ThisWorkbook.Worksheets("SHIPMENTS").Cells(1, 1).Select
End Sub