当从一个工作簿前复制数据时。A1到G1
粘贴到另一个工作簿,我需要B1单元中的vlookup函数
粘贴代码,编写错误代码,如何跳过b1单元或如何在b1单元中编写vlookup函数
任何一个人都可以为这个场景编写代码
我是vba的新手--请帮助我
发布于 2022-12-03 00:40:34
这是将范围从一个工作簿复制到另一个工作簿的一般或最基本的方法。
' > Indicate we want excel to stop us from using undeclared variables.
' This is useful for ensuring we haven't mis-spelled any variables.
' There are more important reasons for it, but for a beginner, this is a good start.
Option Explicit
' > Good Clear Naming for later debugging.
Sub Copy_And_Paste_Salad_Costing_Data()
' > Declare Variables and Variable Types
Dim SourceWB As Workbook
Dim TargetWB As Workbook
' > Set Object Variables
Set SourceWB = ThisWorkbook
Set TargetWB = Workbooks("NameOfMyWorkbook.xlsx")
' > Preform Copy/Paste Operation
SourceWB.Worksheets("Sheet1").Range("B2:C5").Copy
TargetWB.Worksheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
' OR Paste:=xlPasteValues or... many other options
End Sub希望您能够理解它是如何工作的,并使它为您的项目工作。请记住,您不能将数据复制到或从关闭的工作簿中复制。
https://stackoverflow.com/questions/74622951
复制相似问题