简体   繁体   English

VBA代码将单元格从sheet_A复制到sheet_B

[英]VBA code to copy a cell from sheet_A to sheet_B

I have two sheets: 我有两张纸:

SheetA has a list of employee Nr. SheetA列出了员工编号。

Sheet B has a form that needs to be filled out AND printed with each employee numbers on it (then vlookup formulas fill out the rest) 表格B具有需要填写的表格,并在表格上印有每个员工的编号(然后,vlookup公式将填写其余表格)

Now I can copy paste each employee ID manually, but there are 330+ employees, that is a bit too much. 现在,我可以手动复制粘贴每个员工ID,但是有330多名员工,这有点太多了。

I would like to copy cell A2 in Sheet_A, paste it into cell A2 Sheet_B AND print the form, then go to cell A3 in Sheet_A copy it, paste it into A2 in Sheet_B and so on... I would like to repeat this process 337 times. 我想复制Sheet_A中的单元格A2,将其粘贴到单元格A2 Sheet_B中并打印表格,然后转到Sheet_A中的单元格A3,将其复制,粘贴到Sheet_B中的A2中,依此类推...我想重复此过程337次。

在此处输入图片说明

在此处输入图片说明

I created this macro, but I don't know how to make it always choose the next cell in Sheet_A AND repeat itself 337 times. 我创建了此宏,但我不知道如何使它始终选择Sheet_A中的下一个单元格并重复337次。 (or depending on how many employees we have at a certain time) (或取决于我们在特定时间有多少员工)

Sub Copy_Cell()
' Copy_Cell Macro

    Sheets("Sheet A").Select
    Range("A2").Select
    Selection.Copy
    Sheets("Sheet B").Select
    Range("A2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub

You just need to loop through each of your rows: 您只需要遍历每一行:

Sub Copy_Cell()
    Dim r As Long
    'Use a "With" block to save having to constantly type "Worksheets("Sheet A")"
    'inside the block
    With Worksheets("Sheet A")
        'Loop through all values in column A, thus saving the trouble of 
        'hard-coding the last row number to be used
        For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            'Just copy the value directly from one worksheet to another, thus
            'avoiding copy/paste
            Worksheets("Sheet B").Range("A2").Value = .Cells(r, "A").Value
            Worksheets("Sheet B").PrintOut Copies:=1, _
                                           Collate:=True, _
                                           IgnorePrintAreas:=False
        Next r
    End With
End Sub
    Sub Copy_Cell() ' Copy_Cell Macro

Dim i as Integer
For i = 1 To 337
    Sheets("Sheet A").Activate
    ActiveSheet.Cells(i + 1, 1).Select
    Selection.Copy
    Sheets("Sheet B").Activate
    Range("A2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
Next i
    End Sub Image Image
Sub Copy_Cell()
    Dim row as Integer
    Do While row <= 337
        Sheets("Sheet A").Activate
        Sheets("Sheet A").Cells(row + 1, 1).Copy
        Sheets("Sheet B").Activate 
        Range("A2").Select
        ActiveSheet.Paste 
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        row = row + 1
    Loop
End sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA从工作表“ A”复制单元格到工作表“ B”中的合并单元格 - VBA to copy cell from Sheet“A” to merged cells in Sheet“B” EXCEL VBA:将行从工作表A复制到工作表B的末尾 - EXCEL VBA: Copy Rows from Sheet A to end of Sheet B 根据单元格值从可变工作表名称复制的 VBA 代码 - VBA code to copy from a variable sheet name based on cell value 如果工作表 1 中的 B2 与工作表 3 上的任何单元格匹配,请从工作表 3 中复制下一个单元格。(复制到工作表 1) - If B2 in sheet 1 matches any cell on sheet 3, copy the next cell from sheet 3. (copying to sheet 1) VBA-将工作表中的单元格复制到Outlook电子邮件中 - VBA - Copy Cell from Sheet into Outlook email VBA 将遍历每一行的代码,然后将数据从原始工作表复制/粘贴到目标工作表中的正确单元格 - VBA Code that will iterate through each Row, and then copy/paste data from the origin sheet to the correct cell in the destination sheet 使用VBA将对单元格的引用从图纸2复制到图纸1 - Using VBA to copy a Reference to a Cell from Sheet 2 to Sheet 1 用于分隔单元格字符串并将其复制到不同工作表中的下一行的 VBA 代码 - VBA code to separate cell string and copy it to next rows in a different sheet VBA从另一个单元格中的工作表复制特定单元格 - VBA Copy a specific Cell from a sheet in an another cell 当宏从另一张工作表运行时,如果单元格 C 为空白,则用于清除单元格 A 和 B 内容的 VBA 代码 - VBA code to clear contents of cell A and B if cells C blank when macro runs from another sheet
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM