用于从几张纸复制和粘贴数据的宏

时间:2019-09-11 15:49:31

标签: excel vba for-loop copy

我创建了几个宏来将数据复制并粘贴到另一个工作簿中。 各个宏运行正常,但是当我将它们组合成一个宏时 宏,那么第一位将运行,但会给出运行时错误

我尝试将with与语句一起使用,但是代码停止运行 在'Balance Sheet With Worksheets("Balance sheet")

Copy First sheet "Key financials & employees."
         Sub Complete_Macro()
         ' Key_financials
         ' With Worksheets("Key financials & employees")
         ' Worksheets("Key financials & employees").Activate
           Range("A1").Select
          With Selection
          .Orientation = 0
          .AddIndent = False
          .ShrinkToFit = False
          .ReadingOrder = xlContext
          .MergeCells = False
           End With
           Selection.Locked = False
           Selection.FormulaHidden = False

           Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
           Selection.Copy
           Workbooks("Consolidated.xlsx").Activate
           Worksheets("Key_financials_and_employees").Select
           Range("G1").End(xlDown).Select
           ActiveCell.Offset(1, -6).Activate
           Selection.PasteSpecial PAste:=xlPasteAll, Operation:=xlNone, 
           SkipBlanks:=False, Transpose:=True

           End With
          '---Code stops working when the macro is ready ti to copy the 
            second sheet-------
          'Balance Sheet
           With Worksheets("Balance sheet")
           Worksheets("Balance sheet").Activate
           Range("A1").Select
           With Selection
           .Orientation = 0
           .AddIndent = False
           .ShrinkToFit = False
           .ReadingOrder = xlContext
           .MergeCells = False
            End With
            Selection.Locked = False
            Selection.FormulaHidden = False

            Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
            Selection.Copy
            Workbooks("Consolidated.xlsx").Activate
            Worksheets("Balance_sheet").Select
            Range("G1").End(xlDown).Select
            ActiveCell.Offset(1, -6).Activate
            Selection.PasteSpecial PAste:=xlPasteAll, Operation:=xlNone, 
            SkipBlanks:=False, Transpose:=True
            End With
            End Sub

0 个答案:

没有答案
相关问题