Excel 2010 粘贴值

发布于 2025-01-08 03:33:00 字数 717 浏览 4 评论 0原文

Dim ws As Worksheet, wbREF As Workbook
Set ws = ActiveSheet
Set wbREF = Workbooks.Open("ALSP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("N7")         'copy to original sheet
wbREF.Close False

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("FLSP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("Z7")         'copy to original sheet
wbREF.Close False

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("GASP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("AL7")         'copy to original sheet
wbREF.Close False

我现在正在使用这个宏,效果很好。我的问题是关于工作簿“GASP”,其中有公式。该宏不会复制我需要的值。任何人都可以建议解决方法。谢谢

Dim ws As Worksheet, wbREF As Workbook
Set ws = ActiveSheet
Set wbREF = Workbooks.Open("ALSP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("N7")         'copy to original sheet
wbREF.Close False

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("FLSP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("Z7")         'copy to original sheet
wbREF.Close False

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("GASP.xls")      'you may want to put the full path here

Range("B7:L61").Copy ws.Range("AL7")         'copy to original sheet
wbREF.Close False

I am now using this macro which works great. My question is for the workbook "GASP" which has formulas in it. This marco does not copy over the values which I need. Can anyone suggest a work around. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无力看清 2025-01-15 03:33:00

首先,您实际上只需要在宏顶部出现一次这一行:

Set ws = ActiveSheet

接下来,要仅复制值,您需要切换到两行复制/粘贴命令:

Set wbREF = Workbooks.Open("GASP.xls")      'you may want to put the full path here

Range("B7:L61").Copy 
ws.Range("AL7").PasteSpecial xlPasteValues  'copy to original sheet
wbREF.Close False

First, you only really need this one line once at the top of your macro:

Set ws = ActiveSheet

Next, to copy VALUES only, you need to switch to a two-line copy/paste command:

Set wbREF = Workbooks.Open("GASP.xls")      'you may want to put the full path here

Range("B7:L61").Copy 
ws.Range("AL7").PasteSpecial xlPasteValues  'copy to original sheet
wbREF.Close False
没︽人懂的悲伤 2025-01-15 03:33:00

我认为你想要做的是让宏复制值而不仅仅是公式。检查下面的代码

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("GASP.xls")

Range("B7:L61").Copy
ws.Range("AL7").PasteSpecial xlPasteValues
wbREF.Close False

同时确保 excel 已打开自动计算。您可以在“公式”功能区中检查这一点。最后要注意的一件事是,您需要小心验证您的推荐人。每当您调用“Range”函数时,明智的做法是指定包含该范围的工作簿和工作表。像这样:

ThisWorkbook.Sheets("Sheet1").Range("Al7")

或者

With ThisWorkbook.Sheets("Sheet1")
     Set rng = .Range("Al7")
End With

I think what you want to do is have the macro copy the values and not just the formulas. Check the out code below

Set ws = ActiveSheet
Set wbREF = Workbooks.Open("GASP.xls")

Range("B7:L61").Copy
ws.Range("AL7").PasteSpecial xlPasteValues
wbREF.Close False

Also make sure excel has Automatic Calculation turned on. You can check this in the "Formulas" Ribbon. One final thing to be aware of is that you need to be careful about qualifying your references. Whenever you call the "Range" function, it is wise to specify the workbook and the worksheet on which that range is contained. Like this:

ThisWorkbook.Sheets("Sheet1").Range("Al7")

or

With ThisWorkbook.Sheets("Sheet1")
     Set rng = .Range("Al7")
End With
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文