链接来自两个不同工作簿的列 [英] Link columns from two different workbooks

查看:62
本文介绍了链接来自两个不同工作簿的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在工作簿1表2列B:J中输入的数据链接到工作簿2表1列B:J.它们都在同一网络上,我具有链接各个单元的基本代码,但是要在不弄乱工作簿2上输入的数据的情况下对主日志(工作簿1)进行更改是很困难的.

I'm trying to link data entered in Workbook 1 Sheet 2 Columns B:J to Workbook 2 sheet 1 Columns B:J. They're both on the same network and I have basic code to link the individual cells, but it's difficult to make changes to the Master log (workbook 1) without messing up data entered on workbook 2.

这是我要使用的代码,但出现错误,提示我在 Sub foo2()中没有源,但是老实说,我不知道这意味着什么,甚至没有.我刚刚从另一篇文章中获得了这段代码,并试图使其正常工作.我在这里更改了名称,但我知道该路径要输入什么.老实说,我什至不知道这是否是我要达到的正确代码.

This is the code I'm trying to use but I get an error saying I don't have a source at Sub foo2() but I honestly have no idea what that means or even does. I just got this code from another post and am trying to get it to work. I changed the names here but I know what to enter for the path. I honestly don't even know if this is the right code for what I am trying to acheive.

Sub foo2()
Dim x As Workbook
Dim y As Workbook
On Error GoTo Errorcatch

'## Open both workbooks first:
Set x = Workbooks.Open(" S:\Blah\Blah FRC\Blah\Workbook 1 ")
Set y = Workbooks.Open(" S:\Blah\Blah FRC\Blah\Workbook 2 ")

'Now, transfer values from x to y:
y.Sheets("1").Range("B2:2000").Value = x.Sheets("1").Range("B2:B2000")

'Close x:
x.Close

End Sub

Exit Sub

Errorcatch:
 MsgBox Err.Description

推荐答案

也许试试看:

Sub foo2()
  Dim x As Workbook
  Dim y As Workbook

  '## Open both workbooks first:
  Set x = Workbooks.Open(" S:\Blah\Blah FRC\Blah\Workbook 1 ")
  Set y = Workbooks.Open(" S:\Blah\Blah FRC\Blah\Workbook 2 ")

  'Now, transfer values from x to y:
  y.Sheets("1").Range("B2:2000").Value = x.Sheets("1").Range("B2:B2000")

  'Close x:
  x.Close

End Sub

我从没有见过在子外部有退出子"的东西,而且我知道这可能会导致调试错误.

Having an "Exit Sub" outside of the sub is never something I have seen, and I see how that could cause a debug error.

这篇关于链接来自两个不同工作簿的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆