简体   繁体   English

复制同一行中不同列的单元格,并粘贴到另一个工作表上同一行的不同列

[英]Copy cells from different columns on same row, and paste to different columns on same row on another sheet

I have successfully written code that will copy a cell, paste into a cell on another page and then wash rinse repeat for 3 other columns. 我已经成功编写了代码,可以复制一个单元格,粘贴到另一个页面上的单元格中,然后再冲洗另外3个列的冲洗重复。 See below: 见下文:

Sub Click()

Dim amattuid As String
Dim finalrow As Integer
Dim i As Integer


Application.ScreenUpdating = False

Sheets("Buckhalter VB").Range("A6:G200").ClearContents

amattuid = Sheets("Buckhalter VB").Range("B3").Value
finalrow = Sheets("Current Heirarchy").Range("BM2000").End(xlUp).Row
repattuid = Sheets("Buckhalter VB").Range("A6").Value

For i = 4 To finalrow
    If Sheets("Current Heirarchy").Cells(i, 65) = amattuid Then
        Sheets("Current Heirarchy").Cells(i, 46).Copy
        Sheets("Buckhalter VB").Range("A200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        Sheets("Current Heirarchy").Cells(i, 2).Copy
        Sheets("Buckhalter VB").Range("B200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        Sheets("Current Heirarchy").Cells(i, 48).Copy
        Sheets("Buckhalter VB").Range("C200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        Sheets("Current Heirarchy").Cells(i, 49).Copy
        Sheets("Buckhalter VB").Range("G200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        End If
Next i

Application.ScreenUpdating = True

End Sub

This works, but I am wondering if there is a way to streamline it. 这有效,但我想知道是否有办法简化它。 So it copies all of the cells at once, and then pastes them out at once into the designated locations. 因此,它会立即复制所有单元格,然后立即将它们粘贴到指定位置。

Try this : 试试这个 :

Sub Click()

Dim amattuid As String
Dim finalrow As Integer
Dim i As Integer


Application.ScreenUpdating = False

Sheets("Buckhalter VB").Range("A6:G200").ClearContents

amattuid = Sheets("Buckhalter VB").Range("B3").Value
finalrow = Sheets("Current Heirarchy").Range("BM2000").End(xlUp).Row
repattuid = Sheets("Buckhalter VB").Range("A6").Value

For i = 4 To finalrow
    If Sheets("Current Heirarchy").Cells(i, 65) = amattuid Then
        Sheets("Buckhalter VB").Range("A200").End(xlUp).Offset(1, 0) = Sheets("Current Heirarchy").Cells(i, 46).Value
        Sheets("Buckhalter VB").Range("B200").End(xlUp).Offset(1, 0) = Sheets("Current Heirarchy").Cells(i, 2).Value
        Sheets("Buckhalter VB").Range("C200").End(xlUp).Offset(1, 0) = Sheets("Current Heirarchy").Cells(i, 48).Value
        Sheets("Buckhalter VB").Range("G200").End(xlUp).Offset(1, 0) = Sheets("Current Heirarchy").Cells(i, 49).Value
        End If
Next i

Application.ScreenUpdating = True

End Sub

暂无
暂无

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

相关问题 如何从一个工作表中复制特定的列并粘贴到第一行中不同范围的另一工作表中? - How to copy specific columns from one sheet and paste in another sheet in a different range at the first row? 不同列中同一行的 2 个单元格中的特定值,如果 - specific values in 2 cells on same row in different columns if 从工作表复制范围,然后粘贴到不同列的另一工作表中 - Copy range from a sheet and paste into another sheet in different columns 当第一个单元格上的值发生变化时,Excel VBA 代码复制一行中的一系列单元格并粘贴到不同的工作表但相同的行/范围 - Excel VBA code to copy a range of cells in a row and paste in a different sheet but same row/range, when the value on 1st cell changes VBA复制来自不同范围的粘贴值,然后粘贴到同一张纸,同一行偏移列上(重复多张纸) - VBA Copy Paste Values From Separate Ranges And Paste On Same Sheet, Same Row Offset Columns (Repeat For Multiple Sheets) 将行中的单元格复制并粘贴到不同的列中 - Copy and paste cells from rows into different columns 从一个范围复制,粘贴到同一行,但列在左边 - Copy From One Range, Paste To The Same Row But Columns To The Left 复制列直到一张纸的最后一行,然后粘贴到另一张纸的下一个空行 - Copy columns until last row from one sheet and paste to the next empty row of another sheet 如果同一行中的不同单元格包含文本,则将单元格复制到另一张工作表 - copy cell to another sheet if a different cell in the same row contains text 如果满足条件,则将行数据从特定列复制到另一张工作表 - If condition met, copy row data from specific columns to a different sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM