![](/img/trans.png)
[英]How do I use the Inputbox in VBA to obtain a range from a user from a already open Excel workbook and paste it into another, standardized workbook?
[英]How do i paste data into another workbook?
我的代碼按我的意願工作,但僅在工作工作簿中。
我想將數據傳輸到另一個工作簿,但如果我更改名稱和路徑,則它不起作用。
EG:在它所在的代碼中
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
像這樣:
Worksheets("SHIPMENTS").Cells(i, 5).Copy Destination:=Worksheets("SI").Cells(b + 1, 2)
更好 - 聲明一些工作表變量並使用它們來避免所有重復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.