简体   繁体   English

Excel VBA:将单元格值从一个工作簿复制到另一个?

[英]excel vba: copy cell value from one workbook to another?

I am trying to copy the value from cell b from the active row on sheet ' SupplierTracking ' when the text 'send survey' is clicked in column BA and paste this in cell A2 on my other workbook ' Supplier Survey ' on the ' Data ' sheet. 我试图从BA列中单击文本“发送调查”时,从工作表“ SupplierTracking ”上的活动行中复制单元格b中的值,并将其粘贴到我的其他工作簿“ Supplier Survey ”中“ Data ”上的单元格A2片。

For some reason I am not getting any error, however nothing is being pasted into the cell A2 on my other workbook. 由于某种原因,我没有收到任何错误,但是没有任何内容粘贴到其他工作簿的单元格A2

could someone please show me where I am going wrong. 有人可以告诉我我要去哪里错了。 thanks in advance 提前致谢

If Target.Column = Range("BA1").Column And Range("BA" & ActiveCell.Row).Value = "Send Survey" Then
Application.ScreenUpdating = False
Dim wb As Workbook
Dim ws1112 As Worksheet
Dim ws2221 As Worksheet
Set ws1112 = Sheets("SupplierTracking")
Set wb = Workbooks.Open("\\{server address}\assets\Supplier Survey.xls")
Set ws2221 = wb.Sheets("Data")
ws2221.Range("A2").Value = ws1112.Range("B" & ActiveCell.Row).Value
'Optional if you want to close the workbook afterwards
wb.Close SaveChanges:=True
Application.ScreenUpdating = True
End If

I managed to resolve the answer to my question, I needed to save activeCell.Row as a string variable like so 我设法解决了我的问题的答案,我需要将activeCell.Row保存为这样的字符串变量

If Target.Column = Range("BA1").Column And Range("BA" & ActiveCell.Row).Value = "Send Survey" Then

Dim wb As Workbook
Dim ws1112 As Worksheet
Dim ws2221 As Worksheet
Dim s As String
Dim r As String
Set ws1112 = Sheets("SupplierTracking")
s = ws1112.Range("B" & ActiveCell.Row).Value
r = ws1112.Range("C" & ActiveCell.Row).Value
Set wb = Workbooks.Open("\\UKSH000-File06\Purchasing\New_Supplier_Set_Ups_&_Audits\assets\Supplier Survey.xls")
Set ws2221 = wb.Sheets("Data")

ws2221.Range("A2").Value = s
ws2221.Range("B2").Value = r
'Optional if you want to close the workbook afterwards
wb.Close SaveChanges:=True

End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM