Sub copy()
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks.Open("C:\Users\Saurabh\Desktop\Book2.xls")
Set y = Workbooks.Open("C:\Users\Saurabh\Desktop\Book1.xls")
x.Sheets("sheet1").Range("G2").Value = x.Sheets("sheet1").Range("A2").Value
y.Sheets("sheet1").Range("H2").Value = x.Sheets("sheet1").Range("B2").Value
End Sub
答案 0 :(得分:1)
在我的机器上工作正常,试试吧
Sub copy()
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks.Open("C:\Users\Saurabh\Desktop\Book2.xls")
Set y = Workbooks.Open("C:\Users\Saurabh\Desktop\Book1.xls")
x.Sheets("sheet1").[A:A].copy x.Sheets("sheet1").[G:G] 'copy column from x [A:A] to x [G:G]
x.Sheets("sheet1").[B:B].copy y.Sheets("sheet1").[H:H] 'copy column from x [B:B] to y [H:H]
End Sub
答案 1 :(得分:0)
只需修复
这
x.Sheets("sheet1").Range("G2").Value = x.Sheets("sheet1").Range("A2").Value
y.Sheets("sheet1").Range("H2").Value = x.Sheets("sheet1").Range("B2").Value
要
x.Sheets("sheet1").Range("G2").Value = y.Sheets("sheet1").Range("A2").Value
x.Sheets("sheet1").Range("H2").Value = x.Sheets("sheet1").Range("B2").Value
答案 2 :(得分:0)
下面的代码可以很好地复制单元格
Sub copy()
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks.Open("C:\Users\user\Desktop\Book2.xlsx")
Set y = Workbooks.Open("C:\Users\user\Desktop\Book1.xlsx")
x.Sheets("sheet1").Range("G2").Value = y.Sheets("sheet1").Range("A2").Value
x.Sheets("sheet1").Range("H2").Value = y.Sheets("sheet1").Range("B2").Value
End Sub
答案 3 :(得分:-1)
我很确定你需要把你的" s"在" sheet1",所以它正确" S heet1"。我相信它区分大小写。