代码 PasteSpecial Excel VBA 宏的问题

Posted

技术标签:

【中文标题】代码 PasteSpecial Excel VBA 宏的问题【英文标题】:Problem with code PasteSpecial Excel VBA macro 【发布时间】:2021-07-25 05:41:27 【问题描述】:

我在写,因为我的宏有问题。您可以在下面找到它:

Workbooks.Open FileName:="xxxxx.xlsx"
Worksheets("xxxx").Activate
Dim A As Long
A = Cells(Rows.Count, 1).End(xlUp).Row + 1

ThisWorkbook.Sheets("Tabelle1").Range("I6").Copy (ActiveWorkbook.Sheets("xxx").Cells(A, 1))
ThisWorkbook.Sheets("Tabelle1").Range("D3").Copy (ActiveWorkbook.Sheets("xxx").Cells(A, 2))
ThisWorkbook.Sheets("Tabelle1").Range("A6").Copy (ActiveWorkbook.Sheets("xxx").Cells(A, 3))
ThisWorkbook.Sheets("Tabelle1").Range("A37").Copy (ActiveWorkbook.Sheets("xxx").Cells(A, 4))
ThisWorkbook.Sheets("Tabelle1").Range("D37").Copy (ActiveWorkbook.Sheets("xxx").Cells(A, 5))

我想将这些单元格从一个文件复制到另一个文件,但只粘贴值。现在它可以工作了,但是复制了所有内容,还有 fr 示例下拉列表:/ 当我尝试这个时:

Workbooks.Open FileName:="F:\Departments\PUBLIKACJE_DLA_INNYCH_DZIALOW\OES(WRO)\08_Before After Kaizen\Rejestr B_A Kaizen FxxWr.xlsx"
Worksheets("FCGWr").Activate
Dim A As Long
A = Cells(Rows.Count, 1).End(xlUp).Row + 1

ThisWorkbook.Sheets("Tabelle1").Range("I6").Copy (ActiveWorkbook.Sheets("FCGWr").Cells(A, 1)).PasteSpecial Paste:=xlPasteValues
ThisWorkbook.Sheets("Tabelle1").Range("D3").Copy (ActiveWorkbook.Sheets("FCGWr").Cells(A, 2)).PasteSpecial Paste:=xlPasteValues
ThisWorkbook.Sheets("Tabelle1").Range("A6").Copy (ActiveWorkbook.Sheets("FCGWr").Cells(A, 3)).PasteSpecial Paste:=xlPasteValues
ThisWorkbook.Sheets("Tabelle1").Range("A37").Copy (ActiveWorkbook.Sheets("FCGWr").Cells(A, 4)).PasteSpecial Paste:=xlPasteValues
ThisWorkbook.Sheets("Tabelle1").Range("D37").Copy (ActiveWorkbook.Sheets("FCGWr").Cells(A, 5)).PasteSpecial Paste:=xlPasteValues

每次出现错误时它都会显示给我,但我不知道它在哪里:/ 我尝试过使用 Selection,例如:Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 但它仍然不起作用:/

你能帮帮我吗? :)(ofc有代码片段,我记得sub xxx()和end sub :))

【问题讨论】:

【参考方案1】:

您的代码应如下所示。

ThisWorkbook.Sheets("Tabelle1").Range("I6").Copy 
ActiveWorkbook.Sheets("FCGWr").Cells(A, 1).PasteSpecial Paste:=xlPasteValues

【讨论】:

以上是关于代码 PasteSpecial Excel VBA 宏的问题的主要内容,如果未能解决你的问题,请参考以下文章

EXCEL VBA 求助

用于将数据粘贴到新表行中的 VBA 宏 - Excel

无法粘贴 - Excel VBA

PowerPoint VBA - 选择性粘贴(增强的图元文件)错误

Excel 到 PowerPoint PasteSpecial 并保持源格式

从 Google 表格复制特定范围并将值粘贴到 excel