macros是否可以粘贴到现有的macros?

我正试图在excel中为我的员工自动化一个stream程。 我写了几个macros来根据用户input更新几件事情。

是否可以复制单元格A28:H28中新创build的信息并将其粘贴到预先存在的macros中的特定行中?

我已经创build了以下这些信息复制,然后打开相关的macros,但不知道是否有可能粘贴到现有的macros(称为“月”)的信息。

Sheets("New Month Or Client").Select Range("A28:H28").Select Selection.Cut Application.CutCopyMode = False Application.Goto Reference:="Month" 

月份macros的代码是:

 Sub Month() ' NewMonth Macro ' AF Report Sheets("AF Report").Select ' Copy & Paste main data Range("AB8:IV41").Select Selection.Copy Range("AC8").Select Selection.PasteSpecial Paste:=xlValues ' Copy & Paste Top Ten data Range("AA49:IW59").Select Selection.Copy Range("AG49").Select Selection.PasteSpecial Paste:=xlValues Range("B32:B41").Select Selection.Copy Range("AA50").Select Selection.PasteSpecial Paste:=xlValues Range("F32:F41").Select Application.CutCopyMode = False Selection.Copy Range("AB50").Select Selection.PasteSpecial Paste:=xlValues Range("D32:D41").Select Application.CutCopyMode = False Selection.Copy Range("AC50").Select Selection.PasteSpecial Paste:=xlValues Range("H32:I41").Select Application.CutCopyMode = False Selection.Copy Range("AD50").Select Selection.PasteSpecial Paste:=xlValues ' MD Report Sheets("MD Report").Select ' Copy & Paste main data Range("AB8:IV41").Select Selection.Copy Range("AC8").Select Selection.PasteSpecial Paste:=xlValues ' Copy & Paste Top Ten data Range("AA49:IW59").Select Selection.Copy Range("AG49").Select Selection.PasteSpecial Paste:=xlValues Range("B32:B41").Select Selection.Copy Range("AA50").Select Selection.PasteSpecial Paste:=xlValues Range("F32:F41").Select Application.CutCopyMode = False Selection.Copy Range("AB50").Select Selection.PasteSpecial Paste:=xlValues Range("D32:D41").Select Application.CutCopyMode = False Selection.Copy Range("AC50").Select Selection.PasteSpecial Paste:=xlValues Range("H32:I41").Select Application.CutCopyMode = False Selection.Copy Range("AD50").Select Selection.PasteSpecial Paste:=xlValues ' KK Report Sheets("KK Report").Select ' Copy & Paste main data Range("AB8:IV41").Select Selection.Copy Range("AC8").Select Selection.PasteSpecial Paste:=xlValues ' Copy & Paste Top Ten data Range("AA49:IW59").Select Selection.Copy Range("AG49").Select Selection.PasteSpecial Paste:=xlValues Range("B32:B41").Select Selection.Copy Range("AA50").Select Selection.PasteSpecial Paste:=xlValues Range("F32:F41").Select Application.CutCopyMode = False Selection.Copy Range("AB50").Select Selection.PasteSpecial Paste:=xlValues Range("D32:D41").Select Application.CutCopyMode = False Selection.Copy Range("AC50").Select Selection.PasteSpecial Paste:=xlValues Range("H32:I41").Select Application.CutCopyMode = False Selection.Copy Range("AD50").Select Selection.PasteSpecial Paste:=xlValues ' AO Report Sheets("AO Report").Select ' Copy & Paste main data Range("AB8:IV41").Select Selection.Copy Range("AC8").Select Selection.PasteSpecial Paste:=xlValues ' Copy & Paste Top Ten data Range("AA49:IW59").Select Selection.Copy Range("AG49").Select Selection.PasteSpecial Paste:=xlValues Range("B32:B41").Select Selection.Copy Range("AA50").Select Selection.PasteSpecial Paste:=xlValues Range("F32:F41").Select Application.CutCopyMode = False Selection.Copy Range("AB50").Select Selection.PasteSpecial Paste:=xlValues Range("D32:D41").Select Application.CutCopyMode = False Selection.Copy Range("AC50").Select Selection.PasteSpecial Paste:=xlValues Range("H32:I41").Select Application.CutCopyMode = False Selection.Copy Range("AD50").Select Selection.PasteSpecial Paste:=xlValues ' TM Report Sheets("TM Report").Select ' Copy & Paste main data Range("AB8:IV41").Select Selection.Copy Range("AC8").Select Selection.PasteSpecial Paste:=xlValues ' Copy & Paste Top Ten data Range("AA49:IW59").Select Selection.Copy Range("AG49").Select Selection.PasteSpecial Paste:=xlValues Range("B32:B41").Select Selection.Copy Range("AA50").Select Selection.PasteSpecial Paste:=xlValues Range("F32:F41").Select Application.CutCopyMode = False Selection.Copy Range("AB50").Select Selection.PasteSpecial Paste:=xlValues Range("D32:D41").Select Application.CutCopyMode = False Selection.Copy Range("AC50").Select Selection.PasteSpecial Paste:=xlValues Range("H32:I41").Select Application.CutCopyMode = False Selection.Copy Range("AD50").Select Selection.PasteSpecial Paste:=xlValues ' Copy Last Month Pasted Data Sheets("Pasted Report").Select Columns("A:AR").Select Application.CutCopyMode = False Selection.Copy Columns("AZ:AZ").Select ActiveSheet.Paste Columns("A:AR").Select Selection.ClearContents ' Clear Aff No's & Device Columns("CT:CV").Select Selection.ClearContents Columns("CX:DB").Select Selection.ClearContents End Sub 

好吧,现在我可以看到你的代码(已经添加到你的问题,但等待同行评议)。

将一系列单元格传递给过程并复制/粘贴值 – 无需每次都select表单或范围; 只是参考他们。

看看OFFSET和RESIZE,因为我希望你可以通过一个单一的范围,并从那里计算其他范围。

以下是我该怎么做:

 Sub Test() Dim wrkSht As Worksheet 'ThisWorkbook is the file containing the VBA code. 'Can also use ActiveWorkbook, Workbooks("Name.xlsx"), etc. For Each wrkSht In ThisWorkbook.Worksheets Select Case wrkSht.Name Case "Sheet1", "Sheet2", "AnotherSheet" 'Do nothing. Case Else With wrkSht Month .Range("AB8:IV41"), .Range("AC8"), _ .Range("AA49:IW59"), .Range("AG49") End With End Select Next wrkSht End Sub Sub Month(Range1 As Range, Range2 As Range, Range3 As Range, Range4 As Range) Range1.Copy Range2.PasteSpecial Paste:=xlValues Range3.Copy Range4.PasteSpecial Paste:=xlValues End Sub